summaryrefslogtreecommitdiff
path: root/src/util
AgeCommit message (Collapse)AuthorFilesLines
2017-04-03util: fix MSVC warning in u_align_u32()Brian Paul1-1/+1
To silence C:\Users\Brian\projects\mesa\src\util/u_vector.h(41) : warning C4146: unary minus operator applied to unsigned type, result still unsigned Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2017-04-03util: #include "c99_compat.h" to fix Windows buildBrian Paul2-0/+2
Otherwise, we were getting the definition for 'inline' by chance from some other preceeding #include. Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2017-04-03util: s/SHA1_H/MESA_SHA1_H/Brian Paul1-2/+2
To follow the convention of other header include guards. Reviewed-by: Jose Fonseca <jfonseca@vmware.com> Reviewed-by: Emil Velikov <emil.l.velikov@gmail.com>
2017-04-03util/u_atomic: provide 64bit atomics where they're missingGrazvydas Ignotas2-0/+76
There are still some distributions trying to support unfortunate people with old or exotic CPUs that don't have 64bit atomic operations. When compiling for such a machine, gcc conveniently inserts a library call to a helper, but it's implementation is missing and we get a linker error. This allows us to provide our own implementation, which is marked weak to prefer a better implementation, should one exist. v2: changed copyright, some style adjustments v3: [mattst88] Print results with AC_MSG_CHECKING/AC_MSG_RESULT Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=93089 Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
2017-03-25util/disk_cache: don't deadlock on premature EOFGrazvydas Ignotas1-17/+26
If we get EOF earlier than expected, the current read loops will deadlock. This may easily happen if the disk cache gets corrupted. Fix it by using a helper function that handles EOF. Steps to reproduce (on a build with asserts disabled): $ glxgears $ find ~/.cache/mesa/ -type f -exec truncate -s 0 '{}' \; $ glxgears # deadlock Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-24util/disk_cache: write cache entry keys to file headerTimothy Arceri1-6/+44
This can be used to deal with key hash collisions from different versions (should we find that to actually happen) and to find which mesa version produced the cache entry. V2: use blob created at cache creation. v3: remove left over var from v1. Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-24util/disk_cache: hash pointer size and gpu name into cache keysGrazvydas Ignotas2-43/+15
This allows to get rid of the arch and gpu name directories. v2: (Timothy Arceri) don't use an opaque data type to store pointer size and gpu name. v3: (Timothy Arceri) use blob to store driver keys just make sure to store null terminator for strings, and make sure blob is defined by disk_cache and not it's users. v4: (Timothy Arceri) fix typo, and make ptr_size a uint8_t. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-03-24util/disk_cache: hash timestamps into the cache keysGrazvydas Ignotas1-51/+26
Instead of using a directory, hash the timestamps into the cache keys themselves. Since there is no more timestamp directory, there is no more need for deleting the cache of other mesa versions and we rely on eviction to clean up the old cache entries. This solves the problem of using several incarnations of disk_cache at the same time, where one deletes a directory belonging to the other, like when both OpenGL and gallium nine are used simultaneously (or several different mesa installations). v2: using additional blob instead of trying to clone sha1 state v3: (Timothy Arceri) don't use an opaque data type to store timestamp. V4: (Timothy Arceri) use blob to store driver keys just make sure to store null terminator for strings, and make sure blob is defined by disk_cache and not it's users. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100091
2017-03-23util/disk_cache: use rand_xorshift128plus() to get our random intTimothy Arceri1-8/+10
Otherwise for apps that don't seed the regular rand() we will always remove old cache entries from the same dirs. V2: assume bits returned by rand are independent uniformly distributed bits and grab our hex value without taking the modulus of the whole value, this also fixes a bug where 'f' was always missing. Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-03-23util/rand_xor: add function to seed randTimothy Arceri2-0/+69
V2: pass the seed to the seed function so that we can isolate its uses. Stop leaking fd when urandom couldn't be read. Reviewed-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-03-23util: move rand_xorshift128plus() to utilsTimothy Arceri3-0/+55
V2: pass the seed to rand_xorshift128plus() so that we can isolate its uses. Reviewed-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
2017-03-22Android: remove host libmesa_utilRob Herring1-35/+0
The host libmesa_util is never used for Android builds, so remove it. Signed-off-by: Rob Herring <robh@kernel.org> Reviewed-by: Tapani Pälli <tapani.palli@intel.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2017-03-22util: automake: beautify sources listEmil Velikov1-3/+3
Remove trailing tabs and sort alphabetically. Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Acked-by: Vedran Miletić <vedran@miletic.net> Acked-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com> Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
2017-03-22util/strndup: move header inclusion as applicableEmil Velikov1-2/+1
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Acked-by: Vedran Miletić <vedran@miletic.net> Acked-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com> Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
2017-03-22util: inline strndup implementation in the headerEmil Velikov3-50/+20
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Acked-by: Vedran Miletić <vedran@miletic.net> Acked-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com> Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
2017-03-22util: consistently use ifndef guards over pragma onceEmil Velikov4-2/+19
Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com> Acked-by: Vedran Miletić <vedran@miletic.net> Acked-by: Juha-Pekka Heikkila <juhapekka.heikkila@gmail.com> Reviewed-by: Edward O'Callaghan <funfunctor@folklore1984.net>
2017-03-22util/sha1: harmonize _mesa_sha1_* wrappersGrazvydas Ignotas2-9/+10
Rather than using 3 different ways to wrap _mesa_sha1_*() to SHA1*() functions (a macro, prototype with implementation in .c and an inline function), make all 3 inline functions. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
2017-03-21util/disk_cache: fix build on platforms where shader cache is disabledTimothy Arceri1-1/+1
2017-03-21util/disk_cache: add a write helperGrazvydas Ignotas1-14/+23
Simplifies the write code a bit and handles EINTR. V2: (Timothy Arceri) Drop EINTR handling. To do it properly we would need a retry limit but it's probably best to just avoid trying to write if we hit EINTR and try again next time we see the program. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-21util/disk_cache: use a helper to compute cache keysGrazvydas Ignotas2-0/+21
This will allow to hash additional data into the cache keys or even change the hashing algorithm easily, should we decide to do so. v2: don't try to compute key (and crash) if cache is disabled Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-20util/disk_cache: check rename resultGrazvydas Ignotas1-2/+6
I haven't seen this causing problems in practice, but for correctness we should also check if rename succeeded to avoid breaking accounting and leaving a .tmp file behind. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-20util/disk_cache: delete .tmp if target existsGrazvydas Ignotas1-1/+3
At the time of target file check, .tmp file is already created and file lock is held, so we should remove the .tmp, like in other error paths. With this, piglit no longer leaves large amount of empty .tmp files behind, which waste directory entries and may interfere with eviction. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-20util/disk_cache: fix stored_keys indexGrazvydas Ignotas1-2/+2
It seems there is a bug because: - 20 bytes are compared, but only 1 byte stored_keys step is used - entries can overlap each other by 19 bytes - index_mmap is ~1.3M in size, but only first 64K is used With this fix for Deus Ex: - startup time (from launch to Feral logo): ~38s -> ~16s - disk_cache_has_key() hit rate: ~50% -> ~96% Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-18util/disk_cache: pass predicate functions file stats directly (v4)Alan Swanson1-34/+21
Since switching to LRU eviction the only user of these predicate functions now resolves directory entry stats itself so pass them directly saving calling fstat and strlen twice (and the expensive strlen is skipped entirely if access time is newer). v2: Update for empty cache dir detection changes v3: Fix passing string length to predicate with the +1 for NULL termination and also pass sb as pointer v4: Missed ampersand for passing sb as pointer Reviewed-by: Grazvydas Ignotas <notasas@gmail.com> Acked-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-17util/build-id: check dlpi_name before strstr callTapani Pälli1-0/+6
According to dl_iterate_phdr man page first object visited is the main program where dlpi_name is an empty string. This fixes segfault on Android when using build-id as identifier. Fixes: d4fa083e11f ("util: Add utility build-id code.") Signed-off-by: Tapani Pälli <tapani.palli@intel.com> Reviewed-by: Plamena Manolova <plamena.manolova@intel.com> Reviewed-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Matt Turner <mattst88@gmail.com>
2017-03-16util/disk_cache: do eviction before creating .tmpGrazvydas Ignotas1-10/+8
cache_put() first creates a .tmp file and then tries to do eviction. The recently added LRU eviction code selects non-empty directory with the oldest access time, but that may easily be the one with just the new .tmp file, especially on Linux where atime is updated lazily (with "relatime" mount option, which is the default). So when cache is small, if random doesn't hit another dir LRU keeps selecting the same dir with just the .tmp and not deleting anything. To fix this (and the tests), do eviction earlier. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-15util/sha1: drop _mesa_sha1_{update, format} return typeEmil Velikov2-7/+4
Unused/unchecked by any of the callers. v2: Fix the glsl cases that have crept in since v1 Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/sha1: rework _mesa_sha1_{init,final}Emil Velikov2-34/+13
Rather than having an extra memory allocation [that we currently do not and act accordingly] just make the API take an pointer to a stack allocated instance. This and follow-up steps will effectively make the _mesa_sha1_foo simple define/inlines around their SHA1 counterparts. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/sha1: add non-typedef name for the SHA1_CTX structEmil Velikov2-1/+4
Using typedef(s) is not always the answer and makes it harder for people to do clever (or one might call nasty) things with the code. Add a struct name which we will use with follow-up commit. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/disk_cache: scale cache according to filesystem sizeAlan Swanson1-3/+8
Select higher of current 1G default or 10% of filesystem where cache is located. Acked-by: Timothy Arceri <tarceri@itsqueeze.com> Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/disk_cache: actually enforce cache sizeAlan Swanson1-1/+5
Currently only a one in one out eviction so if at max_size and cache files were to constantly increase in size then so would the cache. Restrict to limit of 8 evictions per new cache entry. V2: (Timothy Arceri) fix make check tests Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/disk_cache: use LRU eviction rather than random evictionAlan Swanson1-43/+34
Still using fast random selection of two-character subdirectory in which to check cache files rather than scanning entire cache. v2: Factor out double strlen call v3: C99 declaration of variables where used Reviewed-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-15util/disk_cache: don't fallback to an empty cache dir on evictTimothy Arceri1-6/+27
If we fail to randomly select a two letter cache dir, don't select an empty dir on fallback. In real world use we should never hit the fallback path but it can be hit by tests when the cache is set to a very small max value. Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/disk_cache: use a thread queue to write to shader cacheTimothy Arceri1-13/+28
This should help reduce any overhead added by the shader cache when programs are not found in the cache. To avoid creating any special function just for the sake of the tests we add a one second delay whenever we call dick_cache_put() to give it time to finish. V2: poll for file when waiting for thread in test V3: fix poll delay to really be 100ms, and simplify the wait function Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/disk_cache: add helpers for creating/destroying disk cache put jobsTimothy Arceri1-0/+40
V2: Make a copy of the data so we don't have to worry about it being freed before we are done compressing/writing. Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/disk_cache: add thread queue to disk cacheTimothy Arceri1-1/+15
Reviewed-by: Marek Olšák <marek.olsak@amd.com> Reviewed-by: Grazvydas Ignotas <notasas@gmail.com>
2017-03-15util/vk: Add helpers for finding an extension structJason Ekstrand1-0/+17
Reviewed-by: Dave Airlie <airlied@redhat.com>
2017-03-13util/vulkan: Add vk_outarray (v2)Chad Versace1-0/+140
This is a wrapper for a Vulkan output array. A Vulkan output array is one that follows the convention of the parameters to vkGetPhysicalDeviceQueueFamilyProperties(). v2: Replace vk_outarray_is_incomplete() with vk_outarray_status(). For Jason. Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2017-03-13util/u_thread.h: Include stdint.h for int64_t definition.Jose Fonseca1-0/+2
Fixes MinGW build. Trivial.
2017-03-13util/bitscan: use correct signature for ffs/ffsllEmil Velikov2-6/+6
Otherwise we'll get errors such as error: conflicting types for ‘ffs’ error: conflicting types for ‘ffsll’ We might want to improve the heuristics and provide a definition only when a native one is missing. We can address that at a later stage. Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
2017-03-13util/u_queue: make u_queue accessible to cppTimothy Arceri1-0/+8
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-03-12gallium/util: move u_queue.{c,h} to src/utilTimothy Arceri3-0/+442
This will allow us to use it outside of gallium for things like compressing shader cache entries. Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-03-12util: add u_thread.hTimothy Arceri2-0/+90
This is a minimal copy of os_thread.h from gallium in order to move u_queue.{c,h} to this directory. Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-03-12gallium/util: move u_string.h to src/util/u_string.hTimothy Arceri2-0/+205
This will help us move u_queue.c here eventually and also provide string function wrappers for anyone wishing to port disk_cache.c to windows. Reviewed-by: Marek Olšák <marek.olsak@amd.com>
2017-03-10util: remove shebang from format_srgb.pyEmil Velikov1-1/+0
Analogous to earlier commit(s). Signed-off-by: Emil Velikov <emil.velikov@collabora.com> Reviewed-by: Eric Engestrom <eric.engestrom@imgtec.com>
2017-03-09util/disk_cache: fix size subtraction on 32bitGrazvydas Ignotas1-3/+3
Negating size_t on 32bit produces a 32bit result. This was effectively adding values close to UINT_MAX to the cache size (the files are usually small) instead of intended subtraction. Fixes 'make check' disk_cache failures on 32bit. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-09util/disk_cache: fix compressed size calculationGrazvydas Ignotas1-1/+1
It incorrectly doubles the size on each iteration. Fixes: 85a9b1b5 "util/disk_cache: compress individual cache entries" Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Reviewed-by: Timothy Arceri <tarceri@itsqueeze.com>
2017-03-06ralloc: don't leave out the alignment factorGrazvydas Ignotas1-1/+3
Experimentation shows that without alignment factor gcc and clang choose a factor of 16 even on IA-32, which doesn't match what malloc() uses (8). The problem is it makes gcc assume the pointer is 16 byte aligned, so with -O3 it starts using aligned SSE instructions that later fault, so always specify a suitable alignment factor. Cc: Jonas Pfeil <pfeiljonas@gmx.de> Fixes: cd2b55e5 "ralloc: Make sure ralloc() allocations match malloc()'s alignment." Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=100049 Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Tested by: Mike Lothian <mike@fireburn.co.uk> Tested by: Jonas Pfeil <pfeiljonas@gmx.de>
2017-03-06util/disk_cache: fix make checkTimothy Arceri2-17/+18
Fixes make check after 11f0efec2e615f5233d which caused disk cache to create an additional directory.
2017-03-06Revert "glsl: Switch to disable-by-default for the GLSL shader cache"Timothy Arceri1-7/+0
This reverts commit 0f60c6616e93cba72bff4fbfedb72a753ef78e05. Piglit and all games tested so far seem to be working without issue. This change will allow wide user testing and we can decided before the next release if we need to turn it off again. Reviewed-by: Marek Olšák <marek.olsak@amd.com>