Contact lookup is consuming large amounts of CPU time

Discussions related to the firmware code development
ea3ihi
Posts: 87
Joined: Fri Jan 10, 2020 9:28 pm
Location: Barcelona, Spain

Re: Contact lookup is consuming large amounts of CPU time

Post by ea3ihi » Sat Jan 25, 2020 10:26 am

I think there is no need to copy all 1024 contacts into ram, but instead have an index in ram that maps the dmr id with the contact number, so the lookup is performed in ram to obtain the contact number, and then just one contact record is read from flash.

G4EML
Posts: 919
Joined: Sat Nov 16, 2019 10:01 am

Re: Contact lookup is consuming large amounts of CPU time

Post by G4EML » Sat Jan 25, 2020 10:43 am

I had the same idea as David and was typing this response at the same time!
The lookup table could be created once when the radio powers up and would only need to be 5 bytes per ID (3 for the ID and 2 for the index).
To speed up the searching the list could be sorted into ID order, then it could be searched with a binary search.
This would still need 5K of RAM so it may still be too much. It would also slow down the radio power up but probably not by much.
Last edited by G4EML on Sat Jan 25, 2020 10:54 am, edited 1 time in total.

G4EML
Posts: 919
Joined: Sat Nov 16, 2019 10:01 am

Re: Contact lookup is consuming large amounts of CPU time

Post by G4EML » Sat Jan 25, 2020 10:45 am

If there is not enough RAM to implement this then something similar could be done in a spare area of flash, either at radio startup or by the CPS. That would at least reduce the number of flash accesses when looking up an ID.

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Contact lookup is consuming large amounts of CPU time

Post by VK3KYY » Sat Jan 25, 2020 10:57 am

Colin and David

Yes. That would work.

We do have at least 5k of RAM available ( and even more RAM if the linker settings were working correctly )

75mS to load the cache at boot time would not be noticeable

ea3ihi
Posts: 87
Joined: Fri Jan 10, 2020 9:28 pm
Location: Barcelona, Spain

Re: Contact lookup is consuming large amounts of CPU time

Post by ea3ihi » Sat Jan 25, 2020 7:40 pm

I am doing a small fast and dirty test, using a structure that contains a uint32 for the tg/pc id and uint16 for the contact index.

The code can be found at: https://github.com/ea3ihi/OpenGD77/tree/idlookup

I am initialising the cache from the splash screen, probably not the best place but I though a few more ms of splash screen wont hurt.

Code: Select all

void initialiseContactsIndex() {
	struct_codeplugContact_t contact;
	for (int i = 1; i <= 1024; i++)
		{
			codeplugContactGetDataForIndex(i, &contact);
			contactsIndex[i-1].tgNumber = contact.tgNumber;
			contactsIndex[i-1].contactNumber = i;
		}
}

int codeplugContactIndexByTGorPC(int tgorpc, int callType, struct_codeplugContact_t *contact)
{
	for (int i = 1; i <= 1024; i++)
	{
		if (contactsIndex[i-1].tgNumber == tgorpc)
		{
			codeplugContactGetDataForIndex(i, contact);
			if (contact->name[0] != 0xff && contact->tgNumber == tgorpc && contact->callType == callType)
			{
				return i;
			}
		}
	}
	return 0;
}

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Contact lookup is consuming large amounts of CPU time

Post by VK3KYY » Sat Jan 25, 2020 8:49 pm

Thanks David

I agree. Trying to use 3 bytes for the TG/ID instead of a 4 byte int is not necessary at the moment, I think there is enough RAM to hold the extra 1k
And even if you did try to use a 3 byte array for the TG/ID it’s possible the compiler would leave an empty byte, so that the unsigned 16 bit index is on a 4 byte boundary

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Contact lookup is consuming large amounts of CPU time

Post by VK3KYY » Sun Jan 26, 2020 9:28 am

David and Colin

FYI.

I've written a caching system, and I've posted some code to Daniels' PR that does other things to improve the DMR ID etc lookup and caching

https://github.com/rogerclarkmelbourne/ ... 7/pull/407

At the moment, I'm still testing the final part of my cache handling for the functions when the Contacts menu screen adds or removes contacts.

VK3KYY
Posts: 7484
Joined: Sat Nov 16, 2019 3:25 am
Location: Melbourne, Australia

Re: Contact lookup is consuming large amounts of CPU time

Post by VK3KYY » Sun Jan 26, 2020 9:31 am

VK3KYY wrote:
Sun Jan 26, 2020 9:28 am
David and Colin

FYI.

I've written a caching system, and I've posted some code to Daniels' PR that does other things to improve the DMR ID etc lookup and caching

https://github.com/rogerclarkmelbourne/ ... 7/pull/407

At the moment, I'm still testing the final part of my cache handling for the functions when the Contacts menu screen adds or removes contacts.

PS.

Alex also posted some useful information, about how to assign a variable to either of the 2 memory regions in the Lower bank of RAM.

I may also move some of the lager buffers into the Lower area, eg. the buffer that holds the 3 DMR frames of decoded audio, and see if that still works :-)

Post Reply