Bug 338365 - New client request to fetch valgrind version
Summary: New client request to fetch valgrind version
Status: REPORTED
Alias: None
Product: valgrind
Classification: Developer tools
Component: general (other bugs)
Version First Reported In: unspecified
Platform: unspecified Linux
: NOR wishlist
Target Milestone: ---
Assignee: Julian Seward
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-08-19 05:39 UTC by Étienne Dupuis
Modified: 2022-04-20 06:24 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed/Implemented In:
Sentry Crash Report:


Attachments
Patch implementing feature request (2.85 KB, patch)
2014-08-19 05:39 UTC, Étienne Dupuis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Étienne Dupuis 2014-08-19 05:39:30 UTC
Created attachment 88315 [details]
Patch implementing feature request

Greetings,

Please find included a tiny patch to add a new client request to the Valgrind API. This new client requests returns the Valgrind version running the client software.

Why this patch ? Our software performs cpu capability detection using CPUID to be able to use AVX or AVX2 instructions. However, as expected, older versions of Valgrind does not handle these instructions and in that case Valgrind halts. In order to facilitate the use of Valgrind for all developpers, I had code like

if (RUNNING_ON_VALGRIND) 
   isAvxSupported = false;

Since newer versions of Valgrind do implement AVX instructions, I would like to modify my code to something like 

if (RUNNING_ON_VALGRIND && !VALGRIND_IMPLEMENTS_AVX)
  isAvxSupported  = false;

The easiest way I found to check if Valgrind implements AVX or not is to check Valgrind's version number (AVX supports stats with Valgrind 3.8, AVX2 with Valgrind 3.9). Although valgrind.h defines macros holding the version number, I would like to have the runtime value of the version number, as the software is not necessarily run in the same environment as the one it was compiled on. Spanning a system call to run 'valgrind --version' seems a clumsy solution.

Hence I added client request VALGRIND_RUNNING_VERSION which returns the version of the currently running Valgrind. It returns for example 0x00000308 for Valgrind 3.8. It returns 0 if Valgrind is not running or on Valgrind versions not implementing the client request. I thought it was the easiest solution. With this patch, my code would be

if (RUNNING_ON_VALGRIND && (VALGRIND_RUNNING_VERSION < 0x0000308))
  isAvsSupported = false;

Please feel free to amend this patch. I have tested it. I have also included a modification of an XML file which I assume is used to built the documentation; however I am not sure it is the only documentation file that needs modification.

Regards
Comment 1 Julian Seward 2014-08-30 09:54:58 UTC
I don't understand.  Why can't you use the CPUID results even when running
on Valgrind?
Comment 2 Étienne Dupuis 2014-09-08 06:02:57 UTC
I do use CPUID. However, CPUID returns that AVX is supported by the host platform but valgrind (version 3.7) has not implemented AVX, hence when running the application, valgrind complains about an illegal instruction and stops execution.

Perhaps you are suggesting that recent versions of valgrind changes the result of CPUID to return only implemented instruction sets ?
Comment 3 Julian Seward 2014-09-08 10:52:56 UTC
(In reply to Étienne Dupuis from comment #2)
> Perhaps you are suggesting that recent versions of valgrind changes the
> result of CPUID to return only implemented instruction sets ?

As far as I remember, all versions of Valgrind do that.  Please retry
with the SVN trunk and see if you still have the problem.
Comment 4 Étienne Dupuis 2014-09-11 14:13:13 UTC
Indeed, valgrind changes the result of CPUID to return only implemented instruction sets.

Following your comments, I did some experiments and understood what happened.

Running valgrind 3.6.0, CPUID returned SSE4 intruction set supported. However, it reported an unsupported instruction at PBLENDW, hence I concluded that SSE4 support was not yet implemented and that I should not trust CPUID when running on valgrind. However, it turns out I stumbled on a documented bug : https://bugs.kde.org/show_bug.cgi?id=257011 which has been fixed in valgrind 3.6.1.
Comment 5 Étienne Dupuis 2014-09-11 14:16:46 UTC
Regarding the patch, it is nonetheless a very simple client request to fetch the valgrind version currently running.

Although I have now understood that I do not need it in my particuler case, perhaps someone in the future could need it.

This is up to you.

Thanks for your time!
Comment 6 Étienne Dupuis 2022-04-20 06:24:24 UTC
Recently, I stumbled upon https://bugs.kde.org/show_bug.cgi?id=409429. The issue can be workarounded by manually installing a more recent version of valgrind on all my runners, and telling my coworkers to do the same on their development platforms.

I would have liked to include, at the beginning of my executable something like

if (RUNNING_ON_VALGRIND && (VALGRIND_RUNNING_VERSION < 0x0000316))
   abort("Valgrind >= 3.16 required, otherwise expect false positive!");

The patch provided in this ticket would have made that possible. 

Thanks for your time!