UI memory

  • 24 Replies
  • 3080 Views
*

Offline srsa_4c

  • ******
  • 3687
UI memory
« on: 16 / February / 2014, 12:40:10 »
Advertisements
I was tempted to continue the AdditionAgent-thread, but decided not to.

I found out that the Canon UI related routines use a separate memory chunk for dynamic memory allocations. This chunk is allocated early in the boot process:
To find it, locate taskcreate_PhySw in the startup task. The routine above that calls some initialization functions, the first one allocates / initializes UI memory (can be identified by a "UiMemory.c" debugassert, and a call to malloc with 0x61a80 (400000 decimal) as allocation size). Edit: cameras with wide (960px) viewports have 0x927C0 (600000 decimal) bytes UI memory.
A sub-allocator is used for that memory chunk, its initializer function creates a semaphore named "pvm_alloc" (seems to exist on all DryOS cameras). The sub-allocator only seems to provide the 'malloc' and 'free' routines and an additional function that can retrieve the largest free block size (VxWorks cameras have a much more informative eventproc for this, called 'UiMemory_Show').
On newer cameras (such as the a3200), function pointers (located in RAM) are used to hold the allocator and de-allocator function addresses for UI memory.

Now the reason I'm posting this:
The UI memory chunk's size doesn't seem to be camera specific, it's 400000 bytes even on the old a410 (didn't check every camera, there can be exceptions). It might be possible to reduce its size (requires a small change in a port's boot.c), or use its allocator to allocate from it.
Possible risk: cameras operated for a prolonged time could use up the smaller available area faster than usual.

I have tried using the a3200 for a while with a debug display that shows the largest free UI mem chunk, the number went down to ~280k to the end (I was browsing various menus in play/rec mode). I used the following modification (no sigfinder support yet):
Code: [Select]
Index: core/main.c
===================================================================
--- core/main.c (revision 3359)
+++ core/main.c (working copy)
@@ -247,12 +247,13 @@
             camera_info.state.state_shooting_progress = SHOOTING_PROGRESS_DONE;
         }
 
-        i = 0;
+        i = 3;
 
-#ifdef DEBUG_PRINT_TO_LCD
-        sprintf(osd_buf, "%d", cnt ); // modify cnt to what you want to display
+//#ifdef DEBUG_PRINT_TO_LCD
+        extern int get_uimem_size();
+        sprintf(osd_buf, "uimem free: %d", get_uimem_size() ); // modify cnt to what you want to display
         draw_txt_string(1, i++, osd_buf, conf.osd_color);
-#endif
+//#endif
 
         if (camera_info.perf.md_af_tuning)
         {
Index: platform/a3200/lib.c
===================================================================
--- platform/a3200/lib.c (revision 3359)
+++ platform/a3200/lib.c (working copy)
@@ -113,3 +113,11 @@
 
 int vid_get_palette_type()                      { return 3; }
 int vid_get_palette_size()                      { return 256 * 4; }
+
+
+int get_uimem_size()
+{
+    extern int _get_pvm_maxregion(int handle);
+    extern int uimem_handle;
+    return _get_pvm_maxregion(uimem_handle);
+}
Index: platform/a3200/sub/100d/stubs_entry_2.S
===================================================================
--- platform/a3200/sub/100d/stubs_entry_2.S (revision 3359)
+++ platform/a3200/sub/100d/stubs_entry_2.S (working copy)
@@ -12,3 +12,5 @@
 NHSTUB(TurnOnMic,                   0xFF8608E8)
 NHSTUB(TurnOffMic,                  0xFF860914)
 NHSTUB(TurnOffE1,                   0xff83bc20)
+
+NHSTUB(get_pvm_maxregion,           0xFF8114CC)
Index: platform/a3200/sub/100d/stubs_min.S
===================================================================
--- platform/a3200/sub/100d/stubs_min.S (revision 3359)
+++ platform/a3200/sub/100d/stubs_min.S (working copy)
@@ -1 +1,3 @@
 #include "stubs_asm.h"
+
+DEF(uimem_handle, 0x30ac)
« Last Edit: 20 / February / 2014, 18:06:16 by srsa_4c »

*

Offline srsa_4c

  • ******
  • 3687
Re: UI memory
« Reply #1 on: 18 / February / 2014, 20:57:13 »
Attached is a patch that lets visualize the free UI memory size. It's DryOS only (Vx cameras AFAIK all have enough free RAM).
The debug display can be activated with: 'Miscellaneous stuff' -> 'Debug parameters' -> 'Show misc. values'.
'ALL' shows what I think is the total available UI memory, 'MAX' shows the largest free block of this memory.
As next move, I'll probably try to reduce this memory area, and if that works, some real life testing could take place...

*

Offline reyalp

  • ******
  • 11487
Re: UI memory
« Reply #2 on: 01 / March / 2014, 23:50:52 »
Great work. I tried this on d10.

At startup (with ptp connected)
ALL = MAX = 167328

After going through all the rec / play menus and shooting UIs I could think of, it was down to
ALL 144144
MAX 119976

edit: elph140
startup (no ptp)
ALL = MAX = 349656

After going through the modes and menus MAX was about 300000
« Last Edit: 02 / March / 2014, 00:30:07 by reyalp »
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 3687
Re: UI memory
« Reply #3 on: 02 / March / 2014, 09:42:57 »
@reyalp

Thanks, very interesting.
The D10 also has the "usual" 400000 bytes of UI memory, I wonder what could occupy most of it... None of my cameras I tried this on showed such a low amount of free UI mem.
I have a feeling that actually using the built-in printing support could potentially use up significantly more of this memory.

Anyway, this still looks like an opportunity for _some_ ports to get some more free RAM.
Sadly, I don't get a lot of feedback in the SX230 porting thread, I would consider replacing the default EXMEM config with ARAM + reduced UI mem if I did...


*

Offline reyalp

  • ******
  • 11487
Re: UI memory
« Reply #4 on: 02 / March / 2014, 16:07:36 »
@reyalp

Thanks, very interesting.
The D10 also has the "usual" 400000 bytes of UI memory, I wonder what could occupy most of it... None of my cameras I tried this on showed such a low amount of free UI mem.
Yes, that seems odd. I thought it might have something to do with the number of images on the card (~800) but deleting them and rebooting didn't seem to make any difference.

It would be interesting to know if there is a pattern with camera generation / dryos version. Which cameras did you try?
Quote
I have a feeling that actually using the built-in printing support could potentially use up significantly more of this memory.
I admit I haven't gone deep into the direct print menus, and certainly haven't tried to print.
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 3687
Re: UI memory
« Reply #5 on: 02 / March / 2014, 16:27:46 »
Yes, that seems odd. I thought it might have something to do with the number of images on the card (~800) but deleting them and rebooting didn't seem to make any difference.

It would be interesting to know if there is a pattern with camera generation / dryos version. Which cameras did you try?
a3200, a3400, ixus115 so far.
Quote
I admit I haven't gone deep into the direct print menus, and certainly haven't tried to print.
Me neither. I would even say that CHDK's influence on direct printing (and vice versa) is completely unknown in general.

*

Offline reyalp

  • ******
  • 11487
Re: UI memory
« Reply #6 on: 02 / March / 2014, 18:30:00 »
Don't forget what the H stands for.

*

Offline srsa_4c

  • ******
  • 3687
Re: UI memory
« Reply #7 on: 02 / March / 2014, 18:39:25 »
ixus230_elph310hs might be a candidate too: http://chdk.setepontos.com/index.php?topic=11129.msg109393#msg109393
Thx, I'll note this one. I've been thinking about putting one or more "adverts"/banners to wikia, collecting ports with either low memory or overcompressed JPEGs would be a good idea.


Re: UI memory
« Reply #8 on: 03 / March / 2014, 01:28:15 »
Hi srsa_4c,

Sadly, I don't get a lot of feedback in the SX230 porting thread,...
I have done my very best, but i only have one SX230HS.

..., I would consider replacing the default EXMEM config with ARAM + reduced UI mem if I did...
But anyway: If there is a chance to get more ram, i will test all you you say i should test. But i have only the SX230HS.

Bye

*

Offline srsa_4c

  • ******
  • 3687
Re: UI memory
« Reply #9 on: 03 / March / 2014, 15:43:34 »
I have done my very best, but i only have one SX230HS.
Your help is appreciated, but I'd like to see more reports from other people. No official CHDK ports run with reduced UI memory as of now, I'm not 100% sure that doing this doesn't have negative influence on camera stability.

Quote
But anyway: If there is a chance to get more ram, i will test all you you say i should test.
If you want to play with this, you can "steal" some more of this memory by reducing the value on the line that has the comment "// + (steal 128kB from it)" in boot.c. If the free UI memory falls below, say, ~50kB, the camera may crash.

 

Related Topics