aboutsummaryrefslogtreecommitdiff
path: root/idlestat.c
AgeCommit message (Collapse)Author
2019-07-30idlestat: fix number of cpus checkHEADmasterColin Ian King
Currently the a -ve failure value is being handled as an error for the number of CPUs. Also check for zero cpus as this should be considered as invalid. This also stops a zero sized calloc based on zero cpus being reported as an error by static analysis. Signed-off-by: Colin Ian King <colin.king@canonical.com> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2017-04-12Update the version number to v0.8idlestat-0.8Lisa Nguyen
Signed-off-by: Lisa Nguyen <lisa.nguyen@linaro.org>
2016-11-07Fix resource leak in output_cstate_info() and build_cstate_info()Lisa Nguyen
Coverity Scan detected a resource leak in build_cstate_info() and output_cstate_info() functions. Refer to defect #84131. Valgrind confirms the memory leak as well: ==41915== 4,768 bytes in 1 blocks are definitely lost in loss record 6 of 8 ==41915== at 0x4C2F948: calloc (vg_replace_malloc.c:711) ==41915== by 0x40232B: build_cstate_info (idlestat.c:318) ==41915== by 0x403DD1: output_cstate_info (idlestat.c:937) ==41915== by 0x404D53: idlestat_store (idlestat.c:1286) ==41915== by 0x4055A8: main (idlestat.c:1532) Fix this issue by rewritting the syntax for the calloc function inside build_cstate_info(), so the pointer can be easily deferenced later. Also, deallocate any memory that was created locally inside output_cstate_info(). Signed-off-by: Lisa Nguyen <lisa.nguyen@linaro.org>
2016-09-29Fix the version number.idlestat-0.7Daniel Lezcano
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2016-09-08Fix TRACE_IPIIRQ_FORMAT string format width overflow scan issueColin Ian King
cppcheck detected a potential buffer overflow with a %s scanf width format specifier being larger than the destination buffer. Reduce the scan size to match the expected buffer size. Fixes error: [idlestat.c:974]: (error) Width 32 given in format string (no. 2) is larger than destination buffer 'irqname[17]', use %16s to prevent overflowing it. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2016-09-08fix memory leak in cpuidle_get_target_residency, free fpathAColin Ian King
fpath is not being free'd causing a small memory leak, free it. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
2015-11-04initialise ret to 0, fixes an error found by static analysisidlestat-0.6Colin Ian King
clang's scan-build detected the following error "Undefined or garbage value returned to caller" because ret is not intialised. Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
2015-03-12Fix merge_pstatesTuukka Tikkanen
The function merge_pstates did not work as advertised. This patch fixes the implementation. Signed-off-by: Tuukka Tikkanen <idlestat@tic0.net> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
2015-03-10Handle offline cpus gracefullyTuukka Tikkanen
Several parts of idlestat code did not cope with some cpu(s) being offline. This patch adds information to cpu topology data structure to record online status. Online-sensitive parts of the code may query the status using is_cpu_online() and skip performing activities related to offline cpus. The following activities are skipped of cpu is offline: - Trace: Obtaining initial frequency - Trace: Storing initial frequency - Trace: Adding pseudo pstate transition 0 Hz to end of trace - Trace: Storing cpu C-state information - Tracefile_idlestat: Reading cpu C-state information - Topology: Mapping "datas" to "topology" Signed-off-by: Tuukka Tikkanen <idlestat@tic0.net> Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org>
2015-01-22re-enable compile and run on Android platformKoan-Sin Tan
Make it possible to compile with either AOSP and NDK without warnings. For AOSP, putting the idlestat to AOSP_ROOT/external works fine. For NDK, the following command works fine. ndk-build NDK_PROJECT_PATH=`pwd` \ APP_BUILD_SCRIPT=`pwd`/Android.mk \ APP_PLATFORM=19 APP_ABI=armeabi-v7a 1. Most code modifications to eliminate warnings 2. Both AOSP and NDK use -Wl,--gc-sections, which will remove code compiled from tracefile_*.c and *_report.c, so we need -Wl,--no-gc-sections 3. Android basename() is declared in <libgen.h> 4. Android doesn't have old <values.h>, use <floats.h> instead Signed-off-by: Koan-Sin Tan <freedom.tan@linaro.org> Reviewed-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-22Add -Wunused-parameter to CFLAGSTuukka Tikkanen
Android complation checks that all parameters are used. Add check for this condition to default compilation as well. For cases where the parameter is legitimately not used, add a macro UNUSED to flag such cases for the compiler. This macro is defined in a new header file. Currently this macro is defined functional if the preprocessor macro __GNUC__ is defined, otherwise the macro expands to an empty comment. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-22Simplify event counting while loading a traceTuukka Tikkanen
load_text_data_line() has been split out of the original trace file loading loop. The original code incremented event count at the points of code that had successfully completed importing a single event. As the new function additionally now returns a return code indicating success, this incrementation can be done at the call site. This removes the need to pass a pointer to the count variable and allows further cleanup of the code. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-22Remove unused parameter cpu from write_cstate_infoTuukka Tikkanen
The parameter cpu is not used in write_cstate_info. Note: The function is intended as an abstraction for writing cstate information to trace file. As the trace file format may change in future or multiple output formats may be forthcoming, this function is an abstraction for storing the state. Some future format may require the cpu number, so this parameter may be reintroduced later. However, as we currently do not know whether it is needed or not, it can be removed. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-22Energy model: Remove unused parameter optionsTuukka Tikkanen
Function calculate_energy_model (no longer) uses the program options structure. It may have been used earlier for the verbosity control in some messages, but that system has been reworked. Remove the unused paramter. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-22Fix P-state calculationsTuukka Tikkanen
alloc_pstate() searched the array of existing frequencies as if the frequencies were in descending order (by frequency) but then inserted the new frequency as if the frequencies were to be sorted into ascending order. The search order was changed to ascending order. cluster_get_highest_freq() actually returned the lowest active frequency in the cluster. core_get_highest_freq() acted in the similar way. These have been fixed. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-21Energy_model: Don't add phony frequency to templateTuukka Tikkanen
Idlestat adds phony frequency entries to the end of trace file to ensure all the last running state is accounted for. This phony frequency was unsigned int "-1" (aka 2^32-1 or 2^64-1), which was then listed in any energy model template generated from the trace file. This patch changes the phony frequency to 0 and makes the energy model template generation ignore 0 frequency. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-21Idlestat: P-state calculations for cores and clustersTuukka Tikkanen
The P-state (frequency) for cores and clusters was not calculated. This patch adds recording of core/cluster frequency as the highest frequency of all non-idle cpus contained within the core/ cluster. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-21Idlestat: Add command line options for managing trace bufferTuukka Tikkanen
As the kernel trace buffer is a finite resource, the default trace buffer size idlestat sets may either be impossibly large or insufficient to hold the data. This patch adds two new command line options to control buffer size and whether or not it will be polled during the trace period. The polling functionality while tracing is not yet implemented. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-15Idlestat: Fix core/cluster cstatesTuukka Tikkanen
Calls to core_get_least_cstate and cluster_get_least_cstate were not included in the patch that intended to add them. This caused all core/cluster c-states to be recorded as if the core/cluster entered exactly the same state as what was entered by any cpu in the core/cluster that changed its state. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-13idlestat: Check return value in cpuidle_get_target_residencyTuukka Tikkanen
The return value from call to fscanf was previously ignored. Now the function cpuidle_get_target_residency will return -1 if fscanf fails to parse the value. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-13Idlestat: Suppress static analysis false positivesTuukka Tikkanen
The report_ops and trace_ops arrays are created by the linker. Static analysis tool has no idea of this and make a false positive detection for the loops that access the arrays. This patch introduces comments that suppress the detection for the lines in question. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-07Document use of comparison mode until we get a real man pageAmit Kucheria
Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org> Reviewed-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-07Keep program options sorted alphabetically making them easy to findAmit Kucheria
Makes it easier to add/remove options and keep them sync'ed. Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org> Reviewed-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-07Add option -b as a short option for --baseline-traceAmit Kucheria
It should've been part of dd89f9215bf7c2e345716eb09dfa975f1f1d15dc "idlestat: Add support for baseline datas". While we're at it, remove the '-d' option which is not used anymore. Signed-off-by: Amit Kucheria <amit.kucheria@linaro.org> Reviewed-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-05Idlestat: Update copyright boilerplates and bump version to 0.5Tuukka Tikkanen
Many of the source files were missing copyright headers. Headers have been added to all .c and .h files and existing headers were updates with contributor information. The version number was bumped up to 0.5 due to having many new features since last version number update. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-05idlestat: Remove unused functionsTuukka Tikkanen
The functions used to calculate core/cluster c-state statistics from individual cpu statistics are no longer used and can be removed. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-05Idlestat: Calculate core/cluster data properlyTuukka Tikkanen
Current implementation for core/cluster data calculation is to look for intersections of same state residency in cpu data after loading all of the data. This fails to correctly record core/cluster data for cases where all the contained cpus are in a low power state, but are not using the exact same state. To resolve this, core/cluster state needs to be evaluated at the same time as the cpu events are being processes. The store_data() function is modified to record not only the affected cpu changes, but also the affected core and cluster. Supporting changes are added throughout the source tree. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-05Idlestat: Remove unused parameter count from store_data()Tuukka Tikkanen
The function store_data() does not use the parameter count for any purpose. This patch removes the parameter. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-02Idlestat: Remove unused function cluster_data()Tuukka Tikkanen
The function cluster_data() has no callers, remove it. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2015-01-02Idlestat: Save and restore kernel ftrace optionsKoan-Sin Tan
Idlestat modifies the kernel trace options via sysfs interface every time a trace is created. The user may have prefer to have the original trace options restored once idlestat is finished with the task. This patch adds code to save and restore the trace options that might be modified by idlestat. idlestore_store_trace_options(): Saves the options by 1) record the original trace buffer size and 2) scan the whole ftrace event hierarchy, storing the paths of enabled event types into a list. idlestat_restore_trace_options(): Restores the options including buffer size and enabled events. Disables all other events. Signed-off-by: Koan-Sin Tan <freedom.tan@linaro.org> Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-29Idlestat: Merge pstates between main trace and baseline traceTuukka Tikkanen
As pstates are allocated in the pstate arrays only when seen in traces and each trace has its own private arrays, main trace and baseline may end up having different sets of pstates in their arrays. This patch iterates through the pstate arrays and inserts pstate entries into the arrays so that both traces have the same pstates in same order. This allows easy comparison between the two traces. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-29Reports: Add support for allocating and releasing report_dataTuukka Tikkanen
While passing around the per report data pointer has been previously implemented, there was no mechanism for the report ops to allocate or release the data as needed. This patch moves allocation of report_data pointer from struct options to main() and adds calls necessary for allocating (and initializing) and releasing the data. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-29Reports: Add support for baseline c- and p-states in display_*statesTuukka Tikkanen
The functions display_cstates and display_pstates are in control of dumping c/p state information for each cpu. This patch adds handling of baseline states to both functions. If the selected report mode does not provide baseline handling function(s), the operation is silently skipped. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-29Reports: rename misnamed opsTuukka Tikkanen
pstate_single_state and wakeup_single_state have had most of their names copied from the cstate variant. As the items displayed by these functions are frequencies and interrupt sources, rename the functions to pstate_single_freq and wakeup_single_irq. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-29Topology: add support for dumping baseline data for CPUsTuukka Tikkanen
This patch adds relay of baseline data for per-cpu entries when composing the report. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-29Idlestat: Prevent alloc_pstate from creating duplicate entriesTuukka Tikkanen
The existing version of alloc_pstate() can create duplicate entries for the same pstate if called with a frequency value that already exists. Change the semantics so that in case the frequency already exists in the array, the index returned is for the existing frequency. This change allows removal of (now) obsolete function get_current_pstate and merging of pstate entries between main trace and baseline trace for comparison report purposes. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-12idlestat: Add support for baseline datasTuukka Tikkanen
This patch adds command line option for specifying a baseline trace file. If specified, the trace is loaded using idlestat_load and the baseline member in the main datas structure points to the loaded baseline datas structure. As such, this adds no new features itself, but allows implementing a comparison feature. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-12report_ops: Change way of referring to different report formatsTuukka Tikkanen
The initial implementation of default, boxless and csv report formats required making the report format ops structures global. Getoptions() referred directly to these structures when assigning the active ops pointer. This patch adds a name field to the structures and places pointers to the structures in a special segment so that the list of ops structures can be iterated like an array without having to create such an array explicitly. Getoptions() is modified to record only the name and main() will then obtain the actual structure pointer by name. The ops array head and sentinel is combined into the same source files that have been used for trace file ops arrays. The files are renamed to ops_head.c and ops_tail.c. Command line options parsing now checks that there is only one specification of report format. Usage function lists the available formats. -C and -B are retained as shortcuts for -r csv and -r boxless, respectively. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-12report_ops: Add mechanism for report_ops to check program optionsTuukka Tikkanen
Some reports may require some program options to be set, but other reports may not require the same options. To keep details of these checks out of main() and getoptions(), this patch adds a new operation to report_ops for doing these checks when necessary. Pointer to struct program_options is passed to the op. If the options are not suitable for operation, the op must print an error message for the user and return -1. Otherwise the op should return 0. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-12idlestat: Rename print_vrb and make it a real functionTuukka Tikkanen
print_vrb (print verbose) is a preprocessor macro defined in utils.h. It behaves like fprintf(stderr, ...) if the level argument is greater than or equal to current options->verbose value (incremented by one for each -v parameter on command line). Unfortunately the macro does depend on variable "options" being visible in the scope it is used in, which prevents using it in any function that does not have that variable declared in it or passed to it. This patch makes the macro a real function and disconnects the dependency of having options visible at call site. Instead while the options are passed, a call to set_verbose_level() is make whenever the value of options->verbose changes. The name and call semantics are adjusted to increase versatility of the function. Two variants are created: verbose_printf(int min_level, const char *fmt, ...) verbose_fprintf(FILE *f, int min_level, const char *fmt, ...) These two behave like printf and fprintf if level >= current verbose level, otherwise they do nothing and return 0. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-12idlestat: Separate loading of different trace file formatsTuukka Tikkanen
This patch separates loading of different trace file formats to independent functions. In order to call the correct function for each trace file processed, each load function comes with a match function. Pointers to these functions are stored in a new struct trace_ops. In order to avoid static lists of trace file formats (e.g. implemented as static arrays or a number of registration function calls in main), pointers to all trace_ops structures are collected by the linker into a private segment. This creates an implicit array of the pointers, which may then be enumerated starting right after a globally linked element trace_ops_head. A sentinel NULL pointer trails the array. A helper macro EXPORT_TRACE_OPS is added for creating the special pointers. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org> Reviewed-by: Koan-Sin Tan <freedom.tan@linaro.org>
2014-12-12topology: Dynamic allocation for topologiesTuukka Tikkanen
Pre-patch the topology is rooted to a global variable g_cpu_topo_list. This prevents loading multiple traces for comparison. This patch makes the allocation dynamic. The root pointer is stored within struct cpuidle_datas, allowing the idlestat_load() to retain its prototype, but most of the functions defined in topology.c have a new parameter for passing the topology root pointer. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org> Reviewed-by: Koan-Sin Tan <freedom.tan@linaro.org>
2014-12-11idlestat: Do not return negative value from mainTuukka Tikkanen
Return values from programs are unsigned. Replace return -1 with return 1 in main(). Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-05Idlestat: Plug memory leaks from inter() and topologyTuukka Tikkanen
Function inter() may return newly allocated structures or one of the parameters (if the other parameter is NULL). This function is called in a loop from cluster_data(), core_cluster_data() and physical_cluster_data() with one of the parameters often being an earlier return value from inter(). This causes a great number of structure allocations without matching memory releases. Code in topology.c takes the result from *_cluster_data(), but it only releases the top-level structure, without releasing the data pointed to by top-level structure members. This patch plugs both types of leaks. Since the memory pointed to by inter() may or may not be allocated by that call, a new member has been added to struct cpuidle_cstate to indicate the origin of the structure. This patch also adds detection for data aliasing related to inter(), but does not remove the bug. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-05idlestat: Return error from inter() and intersection() on alloc failTuukka Tikkanen
This patch changes the return value of inter() and intersection() on allocation fail to ptrerror(). Previously the return value was NULL, which under normal conditions indicates no overlap between the two sets. Further cascading changes are made to callers of these functions and the callers of callers etc. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-05idlestat: Make allocations consistent and saferTuukka Tikkanen
This patch modifies malloc/calloc/realloc calls in idlestat.c to conform to following rules: 1. Newly allocated memory is zeroed by using calloc instead of malloc or by calling memset after realloc. The only exception is when the newly allocated memory is storage for a string or always completely overwritten with a call to memcpy or a single assignment statement. 2. Calls to memset(ptr, 0, size) that followed calloc have been removed. 3. perror() message body after allocation failure is uniformly __func__, resulting in "func_name: Out of memory". Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-05idlestat: Correct allocation size in inter()Tuukka Tikkanen
The element count has already been incremented by the time of calling realloc in inter(), so adding +1 to the element count is unnecessary. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-05idlestat: Make ptrerror return a non-NULL pointerTuukka Tikkanen
Some functions such as inter() and intersection() use NULL return value to indicate both errors (e.g. out of memory) and a result (empty intersection). Make ptrerror() return a unique non-NULL pointer value so that the error and NULL result can be told apart. Previously the parameter to ptrerror() was unconditionally interpreted as a pointer to string to be passed to perror(). Now the function checks the value and calls perror only if the parameter value is not NULL. A new function, is_err(), has been added to check if any pointer value is equal to ptrerror() return value. error(), ptrerror() and is_err() have been moved to utils.c. The functions that used ptrerror() before this patch have been modified to consistently return ptrerror() instead of NULL in cases of errors (affects the return statements where no call to perror() is desired). Likewise the callers now use is_err() instead of checking for NULL pointer. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org>
2014-12-05idlestat: Add parameter assertions to intersection()Tuukka Tikkanen
The function intersection() uses pointer parameters without checking the validity. Add assert() statements making sure the pointers are not NULL. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>
2014-12-05idlestat: Fix recording of initial and final P-statesTuukka Tikkanen
The initial and final pstates were stored only if the display options at the time of creating the trace file included display of P-states. Since the trace may later be imported with the P-state display on, add the pseudo P-state changes to the trace unconditionally. In addition, the return value of get_trace_ts was never checked for error. The error checking has been added. Since floating point comparison for equality is unreliable, the function now returns only status and the actual data is relayed by modifying memory pointed to by a function parameter. Error messages have been added to the get_trace_ts function. Signed-off-by: Tuukka Tikkanen <tuukka.tikkanen@linaro.org> Reviewed-by: Amit Kucheria <amit.kucheria@linaro.org>