|
From: Nicholas N. <nj...@cs...> - 2005-05-10 21:01:50
|
On Tue, 10 May 2005, Nathi Maus wrote: > Ok, so I run my programm using "valgrind --tool=cachgrind porg" and using > cg_annote I get information at which positions in my source code cache > misses to happen. > But I do I optimize now? What can I change in my programm to avoid a cache > miss? Section 3.3.8 of http://www.valgrind.org/docs/phd2004.pdf has something to say about this: \subsection{Usability Shortcomings} The nature of the information Cachegrind produces is not ideal. With any profiling tool, one wants a minimal ``conceptual distance'' between the information produced, and the action required to act on that information. For example, with traditional time-based profilers that say how much time each function takes, this conceptual distance is quite small---if a function \code{f()} accounts for 80\% of run-time, one knows immediately that speeding it up will have a large effect. By contrast, Cachegrind's conceptual distance is larger, for two reasons. \begin{enumerate} \item The number of cache misses occurring in a section of code does not necessarily relate obviously to the execution time of that section. Ideally, Cachegrind would specify how many cycles of machine time each instruction accounts for. However, given the complexity of modern machines, this is not feasible. One could use crude cost models to approximate cycle counts, but they are so likely to be misleading that this would be more of a hindrance than a help. (However, Section~\ref{Motivating Measurements} provides a rare counter-example.) \item Even if you know a line of source code is causing a lot of cache misses, and you are confident the misses are slowing down the program a lot, it is not always clear what can be done to improve this. It can be strongly indicative that, for example, a data structure could be redesigned. But the results rarely provide a ``smoking gun'', and some non-trivial insight about how the program interacts with the caches is required to act upon them. \end{enumerate} There is no silver bullet; optimising a program's cache utilisation is hard, and often requires trial and error. What Cachegrind does is turn an extremely difficult problem into a moderately difficult one. N |