ZM 1.25.0 Performance Patch - Completed

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
User avatar
kingofkya
Posts: 1110
Joined: Mon Mar 26, 2007 6:07 am
Location: Las Vegas, Nevada

Re: ZM 1.24.4 Performance Patch - Completed

Post by kingofkya »

This is what i love about open software. One user gets an idea in his head. (mastertheknife) Like say performance and it gets done. Hope this get into svn / 1.25.0
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

Hi,

I see the SVN repository was updated again. Here is the patch again, this time rebased against SVN revision 3497 (latest SVN revision as of this post).
EDIT: Attachment removed. Relocated to the bottom of the first post.

mastertheknife
Last edited by mastertheknife on Wed Aug 17, 2011 7:14 am, edited 2 times in total.
Kfir Itzhak.
MrEvoMan
Posts: 55
Joined: Thu Apr 23, 2009 1:25 am

Re: ZM 1.24.4 Performance Patch - Completed

Post by MrEvoMan »

You should really update this to work with the pre-release version of ZoneMinder 1.25.0.

I'm now running it on a new box I got and it seems to be working very well.

I'm trying to now implement your performance patch and the only snag so far is patching zm_event.cpp. I'm having to manually try to do that one.



And in reference to your comment that ZoneMinder is a CPU hog, I think I solved that. The new box is a Dual Xenon Dual Core 3.6ghz (4 total cores). Load even before the performance patch sits about 0.08 with 12 cams all modect'ing. :lol:
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

MrEvoMan wrote:You should really update this to work with the pre-release version of ZoneMinder 1.25.0.

I'm now running it on a new box I got and it seems to be working very well.

I'm trying to now implement your performance patch and the only snag so far is patching zm_event.cpp. I'm having to manually try to do that one.



And in reference to your comment that ZoneMinder is a CPU hog, I think I solved that. The new box is a Dual Xenon Dual Core 3.6ghz (4 total cores). Load even before the performance patch sits about 0.08 with 12 cams all modect'ing. :lol:
Hi,
I did! The post above yours contains the patch against the latest SVN version (3497). I am not sure though that the same SVN revision is the one used in the 1.25.0 preview package, so its probably best to just fetch SVN revision 3497 from zoneminder's SVN repository:

Code: Select all

svn checkout -r 3497 http://svn.zoneminder.com/svn/zm/trunk zm3497
About zm_event.cpp, you can just download it. Its attached to the first post in this thread. This file didn't change between 1.24.4 and latest SVN and is identical, so it'll work.
Let me know of the new load once you have the patch working. Also, try 32bit colour (and use BGR32 if its a local camera) on that processor, it should result in slightly lower CPU usage than 24bit. Experiment..

mastertheknife :D
Kfir Itzhak.
MrEvoMan
Posts: 55
Joined: Thu Apr 23, 2009 1:25 am

Re: ZM 1.24.4 Performance Patch - Completed

Post by MrEvoMan »

Ok, after getting it compiled and running for the most part w/ the default 8bit grayscale, when I change to 32bit color, I start getting this:

Aug 13 13:26:12 titan zma[3142]: INF [Got signal 4 (Illegal instruction), crashing]
Aug 13 13:26:12 titan zma[3142]: ERR [Signal address is 0x10216, no eip]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /lib/libpthread.so.0(+0xf8f0) [0x7f9f216318f0]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma(_Z17ssse3_delta8_rgbaPKhS0_Phm+0x50) [0x4201b0]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x437d27]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x4444a3]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x4099da]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /lib/libc.so.6(__libc_start_main+0xfd) [0x7f9f204a1c4d]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x4095b9]]
Aug 13 13:26:12 titan zma[3142]: INF [Backtrace complete, please execute the following command for more information]
Aug 13 13:26:12 titan zma[3142]: INF [addr2line -e /usr/local/bin/zma() 0x7f9f216318f0 0x4201b0 0x437d27 0x4444a3 0x4099da 0x7f9f204a1c4d 0x4095b9]

It only seems to happen after I change to 32 bit color. If I leave the cams running in 24 bit, the error doesn't seem to occur.
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

MrEvoMan wrote:Ok, after getting it compiled and running for the most part w/ the default 8bit grayscale, when I change to 32bit color, I start getting this:

Aug 13 13:26:12 titan zma[3142]: INF [Got signal 4 (Illegal instruction), crashing]
Aug 13 13:26:12 titan zma[3142]: ERR [Signal address is 0x10216, no eip]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /lib/libpthread.so.0(+0xf8f0) [0x7f9f216318f0]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma(_Z17ssse3_delta8_rgbaPKhS0_Phm+0x50) [0x4201b0]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x437d27]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x4444a3]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x4099da]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /lib/libc.so.6(__libc_start_main+0xfd) [0x7f9f204a1c4d]]
Aug 13 13:26:12 titan zma[3142]: ERR [Backtrace: /usr/local/bin/zma() [0x4095b9]]
Aug 13 13:26:12 titan zma[3142]: INF [Backtrace complete, please execute the following command for more information]
Aug 13 13:26:12 titan zma[3142]: INF [addr2line -e /usr/local/bin/zma() 0x7f9f216318f0 0x4201b0 0x437d27 0x4444a3 0x4099da 0x7f9f204a1c4d 0x4095b9]

It only seems to happen after I change to 32 bit color. If I leave the cams running in 24 bit, the error doesn't seem to occur.
Hi, It crashes in SSSE3 code. Illegal instruction means that your processor doesn't support the instruction the code was trying to execute.
Does your processor have SSSE3? What does cat /proc/cpuinfo | grep ssse3 show?
Also, what is your processor's model\full name?

mastertheknife
Kfir Itzhak.
MrEvoMan
Posts: 55
Joined: Thu Apr 23, 2009 1:25 am

Re: ZM 1.24.4 Performance Patch - Completed

Post by MrEvoMan »

It doesn't list sse3, but when I compiled, I used the -msse2 flag.

Is 32bit sse3 only?
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

MrEvoMan wrote:It doesn't list sse3, but when I compiled, I used the -msse2 flag.

Is 32bit sse3 only?
Hi. The -msse2 is simply needed to get the code to compile without gcc spitting errors about unknown registers.
Don't confuse SSE3 with SSSE3. SSSE3 is an addition to SSE3 and contains some very useful additions to the instruction set.
The difference between 24bit and 32bit in motion detection mode (Modect or Mocord) is that 32bit uses some of SSSE3's instruction set for generating the difference (delta) image, while 24bit uses normal C\C++ code which is slower.
You can see the difference here:
Image

The patch contains automatic detection of SSE2 and SSSE3 presence, by using the "cpuid" assembler instruction.
For some reason believes that your processor supports SSSE3, so the code attempts to use that and when it does, it crashes with "Illegal instruction" which means that the processor doesn't support the instruction used, in other words, doesn't support SSSE3.

mastertheknife
Kfir Itzhak.
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

Hi everyone,

I found that the SSSE3 detection was one bit off, and was actually detecting some other CPU feature instead!
This bug only affects 32bit target colorspace because only 32bit color makes use of the SSSE3 instruction set.
This wrong detection might lead to false positive detection of SSSE3 and zma will crash on startup everytime. A workaround is to use grayscale or 24bit. Or, to turn off ZM_CPU_EXTENSIONS but that will defeat the purpose of using SSE2 and SSSE3 to speed up things and decrease CPU usage.
The first post will be soon updated with a fixed patch for ZM 1.24.4 and for the latest SVN revision.

EDIT: The first post was updated and now contains a fixed patch for ZM 1.24.4 and latest SVN revision (3497 as of this post).

mastertheknife
Kfir Itzhak.
allangood
Posts: 12
Joined: Mon Jun 06, 2011 3:00 pm

Re: ZM 1.24.4 Performance Patch - Completed

Post by allangood »

Hey mastertheknife,

you are my new hero now! :D

I bought a Bluecherry card with (J)MPEG compression (16 channels) and with your patch this cards works like a charm with zoneminder!

Many, many thanks to you!

BTW, you have a wishlist on amazon? :)
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

allangood wrote:Hey mastertheknife,

you are my new hero now! :D

I bought a Bluecherry card with (J)MPEG compression (16 channels) and with your patch this cards works like a charm with zoneminder!

Many, many thanks to you!

BTW, you have a wishlist on amazon? :)
Hi allangood!

Thats awesome to hear! I suppose you are using the JPEG or MJPEG capture palettes for this?
Maybe in the future i will also try adding support for the MPEG capture palette by feeding the captured stream into ffmpeg for decoding.

mastertheknife
Kfir Itzhak.
MrEvoMan
Posts: 55
Joined: Thu Apr 23, 2009 1:25 am

Re: ZM 1.24.4 Performance Patch - Completed

Post by MrEvoMan »

I've been seeming to have some random wierdness that I can't attribute to anything else other than your customizations.

I'm trying to go back to the latest 1.25.0 source (r3501 as of this post) to see if the problems still exist.

I really like most of the changes you made, but here's my short list of "oddities":

- detection is way off. Sometimes, it's super sensitive, othertimes I can wave to the camera with nothing.
- alarms sometimes go on for hours.
- 32bit is flat out flakey. Causes cams to reset (the zm processes) and has locked up a number of my cams.
- motion detection using 32 bit is even worse.
- load spikes for no reason. otherwise, its extremely low loads
- zmu crashes often. often this backtrace: Backtrace: /lib/libpthread.so.0
- image stat highlighting - when you have an alarm frame, it draws around the items that triggered it no longer appear.


Is it possible to more break apart the patch so I can just apply the fixes/changes rather than the SSE2/32bit enhancements?

Thanks for all your hard work though!
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Re: ZM 1.24.4 Performance Patch - Completed

Post by whatboy »

The patched Zoneminder doesn't create the the folder in /usr/local/lib/perl5/site_perl/5.10/zoneminder nor the files in it!!!
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

whatboy wrote:The patched Zoneminder doesn't create the the folder in /usr/local/lib/perl5/site_perl/5.10/zoneminder nor the files in it!!!
Hi,

The installation was not changed, so the issue is probably elsewhere.

mastertheknife
Kfir Itzhak.
mastertheknife
Posts: 678
Joined: Wed Dec 16, 2009 4:32 pm
Location: Israel

Re: ZM 1.24.4 Performance Patch - Completed

Post by mastertheknife »

MrEvoMan wrote:I really like most of the changes you made, but here's my short list of "oddities":

- detection is way off. Sometimes, it's super sensitive, othertimes I can wave to the camera with nothing.
- alarms sometimes go on for hours.
Hi, few days ago i discovered some bugs with the blobs detection, that are probably a result of my patch. I already have a fix for this which i'm testing right now, but in the meanwhile, if you are using blobs motion detection, it doesn't work right and you should use AlarmedPixels or FilteredPixels instead, until i have the fix ready.
Also make sure to pay attention to the blend percent you are using. Getting the motion detection right is something that often takes a while to find the perfect spot. Enabling the diagnostic images might help in that process by showing you whats going on and what is triggering an alarm.
MrEvoMan wrote: - 32bit is flat out flakey. Causes cams to reset (the zm processes) and has locked up a number of my cams.
- motion detection using 32 bit is even worse.
If you have any backtraces or snippets from the system log, that can greatly help!
The generated difference image (delta image) which is used for motion detection is 8bit grayscale image, so motion detection works on 8bit grayscale images, so i'm not sure how motion detection can be worse when using 32bit.
Also keep in mind that the only advantage 32bit has over 24bit is less CPU load on processors with SSSE3 with the camera(s) in motion detection mode (modect or mocord). If your processor doesn't have SSSE3, 24bit is probably a better option because it uses less memory.
MrEvoMan wrote: - load spikes for no reason. otherwise, its extremely low loads
This can be anything on your system, and can be an I/O bottleneck.
MrEvoMan wrote: - zmu crashes often. often this backtrace: Backtrace: /lib/libpthread.so.0
A complete backtrace (including running the addr2line command) will greatly help.
MrEvoMan wrote: - image stat highlighting - when you have an alarm frame, it draws around the items that triggered it no longer appear.
This only works with the Blobs type of motion detection and if the option for creating analysis images is enabled. However you are correct, it doesn't work right with my patch and i'm working on this.
MrEvoMan wrote: Is it possible to more break apart the patch so I can just apply the fixes/changes rather than the SSE2/32bit enhancements?
If your ZM is installed from source then yes, you can just copy any parts that you are interested in and re-compile and re-install your ZM. Keep in mind that some things may not compile or work right, e.g. if you copy the SSE2 code of blend and delta into your ZM, you will most likely experience crashes because the memory has to be aligned on a 16 byte boundary.

It will be great help if i could tackle the issues one by one, with your assistance. For example the SSSE3 detection issue that you discovered is now fixed, thanks to your report and backtrace!
MrEvoMan wrote: Thanks for all your hard work though!
Your welcome, thank you too for reporting issues!

mastertheknife
Kfir Itzhak.
Post Reply