Voodooalert+x264 Logo
US+UK Flagge DE+AT Flagge
Change language:
 

x264 benchmark compilation and installation guide for OpenSolaris 11

OpenSolaris Logo

System prerequisites

To be able to compile and install the x264 benchmark on OpenSolaris 11, some base software like GCC4, autoconf, make etc. is required in their GNU versions. To make sure you have all that, launch the OpenSolaris package manager and install the following packages from all the listed groups. A few of those packages might not be required for the benchmark to compile and operate, but if you install that tool collection as listed, it will at least work for sure:

Additionally to all those packages, we will need a bash shell and the time command, which are however shipped with OpenSolaris anyway.

To assemble optimized code, we also need the yasm assembler, which we will compile from source code ourselves. First, please download yasm:

After that, please unpack the archive: tar -xzvf ./yasm-1.2.0.tar.gz and start with the source code configuration. Other than the upcoming packages, yasm is very well prepared for OpenSolaris and its weird, renamed GNU tools, so this will be relatively easy:

Now please run the following two commands to add the installation binary path to your search path immediately and also permanently, so you can launch all installed programs conveniently:

yasm should now be launchable (you can verify that by running yasm --version), which means we can continue with libav and x264:

The benchmarking software itself

To be able to use x264, we will need the decoding filters of libavcodec (in short libav) and of course the x264 encoder itself, which will be linked against libav in the course of its compilation. Additionally we will need the benchmark input video. Download mirrors for that one can be found at the end of the benchmark results list. If you wish, you may also use ffmpeg/ffms as a replacement for libav.

For simplicities sake we shall assume, that those files are now in the path /home/user/x264src/. On top of that, we will assume that the yasm assembler is available. Please go to that directory on the terminal, and start with libav. First, unpack the archive: tar -xzvf <filename.tgz> after which you will see a new libav folder. Change to that folder and start with the necessary modifications and configurations:

First we need to set the proper environment variables. For stabilities sake it is recommended to forget about aggressive optimizations, besides the basic optimization you shouldn't do any more than telling the compiler about your CPU type. In our example, we will assume an Intel Core 2 type processor. If you'd like to know how to specify other processors, please check out the [GCC documentation].
I would like to additionally mention, that you should under no circumstances use the C(XX)FLAG -pipe! This option is meant to accelerate the process of code compilation, but instead it breaks it on OpenSolaris. Also, this option doesn't do that much anyway. On top of that, we will need to set some OpenSolaris-specific linker flags, as some operating system functions are not implemented in the usual libraries that configure will know from Linux or other Unix derivatives. Some functions that x264 relies on are in libxnet, others in libresolv. Also we need /usr/lib/values-xpg6.o to complement the non-standard libc of OpenSolaris. So let's set the proper LDFLAGS:

It shall be mentioned, that you should not close your terminal window after setting CFLAGS, CXXFLAGS and LDFLAGS, because you will lose those settings when doing so. If you have to kill that window, you will need to set those environment variables again when continueing.

Now we do have a lot of GNU tools on that system already, but all their common file names are already taken by the corresponding Sun tools, which partially work entirely differently, so they would disturb and actually completely break the configuration process. So it's modification time again. First, let's edit the configure script in the libav folder, e.g. with the graphical text editor gedit. After that, you can e.g. hit CTRL+H to bring up the search & replace user interface. Please apply the following replacements. Mind the whitespace at the end of each one, this is important so the search & replace matches only the intended commands and not some functions with similar names:

Now we can start the configuration process for the libav source code. Newer libav versions' configurations can no longer properly set specific assembler code paths while leaving others out of the game on OpenSolaris. So we have to disable all optimizations. Luckily, this is not critical for performance in the case of libav and our intended application:

Now we still need to ensure that all optimizations have been successfully killed off, to ensure that, search for the following patterns in the files listed below: "3DNOW", "3DNOWEXT", "MMX", "MMXEXT" "SSE", "SSE2", "SSE3", "SSSE3", "SSE4", "SSE42", "AVX" und "FMA4". In case some are active, disable them as shown:

Now we need a last modification in favor of our GNU tools done to config.mak, please look for the following string:

INSTALL=install

Replace that with:

INSTALL=ginstall

Now we can build and install the libav suite:

Now libav is readily installed and we can take on the last challenge, x264 itself. First we need to set some new CFLAGS and CXXFLAGS, the LDFLAGS that we have already set for libav can stay the same. As example target platform we shall again assume an Intel Core 2. By the way, you should really not do anything more aggressive than -O1 here, stronger optimizations can very quickly result in defective code here, which will have troubles when calling functions from OpenSolaris' non-standard libc. There will be more about this topic soon:

Now we need to do some search & replace again, to tell configure, that it should better use GNU tools instead of the weird Sun stuff, so let's edit that file:

Additionally, config.guess will need some adaptations, quite similar to what we had to do to configure:

That done, we need to fix some parts of configures operating system detection routine, please look for the following spot in configure:

sunos*|solaris*)
  SYS="SunOS"
  define HAVE_MALLOC_H
  LDFLAGS="$LDFLAGS -lm"
  if cc_check "" /usr/lib/64/values-xpg6.o; then
    LDFLAGS="$LDFLAGS /usr/lib/64/values-xpg6.o"
  else
    LDFLAGS="$LDFLAGS /usr/lib/values-xpg6.o"
  fi
  HAVE_GETOPT_LONG=0
  ;;

Replace that with the following code:

sunos*|solaris*)
  SYS="SunOS"
  define HAVE_MALLOC_H
  LDFLAGS="$LDFLAGS -lm -lxnet -lresolv /usr/lib/values-xpg6.o"
  HAVE_GETOPT_LONG=0
  ;;

Now we can launch the configuration process by starting the script as shown:

Now that configure did its stuff, we need to fix some details in the newly created config.mak as autoconf will have made some wrong decisions that would again result in defective code on OpenSolaris, and also because code linking would not work because of some missing specifications. First, look for a line that looks like this:

CFLAGS=-Wshadow -O3 -ffast-math -O1 -march=core2 -L/usr/local/lib -I/usr/local/include -Wall -I. -I$(SRCPATH) -mfpmath=sse -msse -std=gnu99 -fomit-frame-pointer -fno-tree-vectorize

Replace it with the following line to enable our code to run and link against libc:

CFLAGS=-Wshadow -O1 -march=core2 -L/usr/local/lib -I/usr/local/include -Wall -I. -I$(SRCPATH) -std=gnu99 -fomit-frame-pointer -fno-tree-vectorize

Now for the rest of the linking stuff, look out for the following line:

LDFLAGSCLI = -L. -lavformat -lavcodec -lswscale -lavutil -lm -lz -lbz2 -lpthread -lswscale -lavutil

Replace it with this line, effectively fixing all the linkers problems:

LDFLAGSCLI = -L. -L/usr/local/lib -lavformat -lavcodec -lswscale -lavutil -lm -lz -lbz2 -lpthread -lswscale -lavutil -lxnet -lresolv /usr/lib/values-xpg6.o

To fix the installation routine, we also need to edit the Makefile and look for all indent lines that start with install. That's a lot of code, so I will only show you an exemplary part of it. Look for some stuff like this:

install-lib-dev:
  install -d $(DESTDIR)$(includedir)
  install -d $(DESTDIR)$(libdir)
  install -d $(DESTDIR)$(libdir)/pkgconfig
  install -m 644 $(SRCPATH)/x264.h $(DESTDIR)$(includedir)
  install -m 644 x264_config.h $(DESTDIR)$(includedir)
  install -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig

Now replace all install calls with ginstall, you'll need to do this for the rest of the file in the exact same fashion:

install-lib-dev:
  ginstall -d $(DESTDIR)$(includedir)
  ginstall -d $(DESTDIR)$(libdir)
  ginstall -d $(DESTDIR)$(libdir)/pkgconfig
  ginstall -m 644 $(SRCPATH)/x264.h $(DESTDIR)$(includedir)
  ginstall -m 644 x264_config.h $(DESTDIR)$(includedir)
  ginstall -m 644 x264.pc $(DESTDIR)$(libdir)/pkgconfig

Moreover, please also apply the following replacements in the Makefile:

Now it's about time to build that stuff. If all modifications have been applied cleanly, the compilation and installation should now work smoothly:

After that - hopefully without hiccups - you can verify the functionality by running x264 --version. If that works, and if the binary shows being linked against libswscale and libavformat, everything should be fine, unless you have accidentally built some broken code or compiled some assembler for non-present instruction extensions without noticing it. You can now download the benchmarking script and the input video file:

That file launchbenchmark.sh should be copied into a dedicated benchmarking subfolder that we can just create if there isn't one yet: mkdir -p /home/user/x264benchmark. Besides the script you should also have the input video stream elephantsdream_source.264 in that folder.

Now unfortunately x264 will use a way of CPU core detection that will fail on OpenSolaris despite it being a Unix system. That results in x264 having strictly no idea how many logical processors there are in the system. When that happens, x264 will only launch a single worker thread, and hence will only load one logical processor core, even if we have multithreading support on board. Luckily, there is an easy fix for this, we just need to add a little something to our launchbenchmark.sh, telling x264 how many worker threads it's supposed to spawn. For that, we should follow the old x264 rule:

So, for a CPU with 4 cores, that would make 6 threads. For a CPU with 4 cores and hyper threading (=8 logical CPUs) that would make 12 threads. If by any chance you have a triple core that simple old formula won't work of course, but in that case just round up to 5 threads. The maximum number of workers is by the way 32, at least at the time of writing, so you can't spawn more worker threads than that. So to make that little change to the benchmark, open up launchbenchmark.sh with gedit, and add the option after both occurences of --cqm flat:

Here, n is the amount of worker threads, so e.g. --threads 12 for a system with 8 logical CPUs. Now with that, nothing should stand in the way of using multiple CPUs, cores and hyper threads anymore!

So now you can basically just launch the benchmark, so just enter the following line after ensuring that the script is executable (chmod +x ./launchbenchmark.sh) and while of course sitting in /boot/home/x264benchmark:

That could look somewhat like this (Click to enlarge):

OpenSolaris 11 Screenshot

After completion, the result can be seen right next to the string "Real".

Depending on the host machine that might take some hours, in extreme cases even days, weeks or months. If you have problems with this guide or if there are any additional questions about the x264 benchmark on OpenSolaris 11, please refer to the [according forum thread] and ask there. The forum is german, but if you ask in english, you will still get a reply, at least by me. :)

[Back to the x264 benchmark results list]

[Comment on this guide]