Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame] | 1 | /* |
| 2 | <:copyright-BRCM:2014:proprietary:standard |
| 3 | |
| 4 | Copyright (c) 2014 Broadcom Corporation |
| 5 | All Rights Reserved |
| 6 | |
| 7 | This program is the proprietary software of Broadcom Corporation and/or its |
| 8 | licensors, and may only be used, duplicated, modified or distributed pursuant |
| 9 | to the terms and conditions of a separate, written license agreement executed |
| 10 | between you and Broadcom (an "Authorized License"). Except as set forth in |
| 11 | an Authorized License, Broadcom grants no license (express or implied), right |
| 12 | to use, or waiver of any kind with respect to the Software, and Broadcom |
| 13 | expressly reserves all rights in and to the Software and all intellectual |
| 14 | property rights therein. IF YOU HAVE NO AUTHORIZED LICENSE, THEN YOU HAVE |
| 15 | NO RIGHT TO USE THIS SOFTWARE IN ANY WAY, AND SHOULD IMMEDIATELY NOTIFY |
| 16 | BROADCOM AND DISCONTINUE ALL USE OF THE SOFTWARE. |
| 17 | |
| 18 | Except as expressly set forth in the Authorized License, |
| 19 | |
| 20 | 1. This program, including its structure, sequence and organization, |
| 21 | constitutes the valuable trade secrets of Broadcom, and you shall use |
| 22 | all reasonable efforts to protect the confidentiality thereof, and to |
| 23 | use this information only in connection with your use of Broadcom |
| 24 | integrated circuit products. |
| 25 | |
| 26 | 2. TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" |
| 27 | AND WITH ALL FAULTS AND BROADCOM MAKES NO PROMISES, REPRESENTATIONS OR |
| 28 | WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH |
| 29 | RESPECT TO THE SOFTWARE. BROADCOM SPECIFICALLY DISCLAIMS ANY AND |
| 30 | ALL IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, |
| 31 | FITNESS FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR |
| 32 | COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR CORRESPONDENCE |
| 33 | TO DESCRIPTION. YOU ASSUME THE ENTIRE RISK ARISING OUT OF USE OR |
| 34 | PERFORMANCE OF THE SOFTWARE. |
| 35 | |
| 36 | 3. TO THE MAXIMUM EXTENT PERMITTED BY LAW, IN NO EVENT SHALL BROADCOM OR |
| 37 | ITS LICENSORS BE LIABLE FOR (i) CONSEQUENTIAL, INCIDENTAL, SPECIAL, |
| 38 | INDIRECT, OR EXEMPLARY DAMAGES WHATSOEVER ARISING OUT OF OR IN ANY |
| 39 | WAY RELATING TO YOUR USE OF OR INABILITY TO USE THE SOFTWARE EVEN |
| 40 | IF BROADCOM HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES; |
| 41 | OR (ii) ANY AMOUNT IN EXCESS OF THE AMOUNT ACTUALLY PAID FOR THE |
| 42 | SOFTWARE ITSELF OR U.S. $1, WHICHEVER IS GREATER. THESE LIMITATIONS |
| 43 | SHALL APPLY NOTWITHSTANDING ANY FAILURE OF ESSENTIAL PURPOSE OF ANY |
| 44 | LIMITED REMEDY. |
| 45 | :> |
| 46 | */ |
| 47 | |
| 48 | #include <bcmos_system.h> |
| 49 | #include "bcmolt_time_measurement.h" |
| 50 | |
| 51 | typedef struct |
| 52 | { |
| 53 | dev_log_id log_id; |
| 54 | uint32_t num_cycles_for_average; |
| 55 | F_bcmolt_time_measurement_ticks_to_ns ticks_to_ns; |
| 56 | F_bcmolt_time_measurement_avg_done avg_done; |
| 57 | uint32_t cycle_num; |
| 58 | } bcmolt_time_measurement_context; |
| 59 | |
| 60 | static bcmolt_time_measurement_context time_measurement_context = { DEV_LOG_INVALID_ID, 0, NULL, NULL, 0 }; |
| 61 | |
| 62 | void bcmolt_time_measurement_init( |
| 63 | dev_log_id log_id, |
| 64 | uint32_t num_cycles_for_average, |
| 65 | F_bcmolt_time_measurement_ticks_to_ns ticks_to_ns, |
| 66 | F_bcmolt_time_measurement_avg_done avg_done) |
| 67 | { |
| 68 | time_measurement_context = (bcmolt_time_measurement_context) |
| 69 | { log_id, num_cycles_for_average, ticks_to_ns, avg_done, 0 }; |
| 70 | } |
| 71 | |
| 72 | void bcmolt_time_measurement_sample_end(uint64_t *total_ticks, uint32_t *num_of_samples, const char *measurement_name) |
| 73 | { |
| 74 | /* Don't do anything if we haven't run enough cycles to produce an average. */ |
| 75 | if (time_measurement_context.cycle_num < (time_measurement_context.num_cycles_for_average - 1)) |
| 76 | { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (*num_of_samples != 0 && time_measurement_context.ticks_to_ns != NULL) |
| 81 | { |
| 82 | /* Convert the sample time from ticks to ns. */ |
| 83 | uint64_t duration_average_ns = time_measurement_context.ticks_to_ns(*total_ticks / *num_of_samples); |
| 84 | |
| 85 | /* The ":" is used as delimiter when importing to excel. */ |
| 86 | BCM_LOG( |
| 87 | DEBUG, |
| 88 | time_measurement_context.log_id, |
| 89 | ":%s: %llu.%03llu us (%u hits)\n", |
| 90 | measurement_name, |
| 91 | (long long unsigned int)(duration_average_ns / 1000), |
| 92 | (long long unsigned int)(duration_average_ns % 1000), |
| 93 | *num_of_samples); |
| 94 | } |
| 95 | |
| 96 | *total_ticks = 0; |
| 97 | *num_of_samples = 0; |
| 98 | } |
| 99 | |
| 100 | void bcmolt_time_measurement_cycle_end(void) |
| 101 | { |
| 102 | if (time_measurement_context.cycle_num == (time_measurement_context.num_cycles_for_average - 1)) |
| 103 | { |
| 104 | if (time_measurement_context.avg_done != NULL) |
| 105 | { |
| 106 | time_measurement_context.avg_done(); |
| 107 | } |
| 108 | |
| 109 | /* Print a delimiting line. */ |
| 110 | BCM_LOG(DEBUG, time_measurement_context.log_id, "\n"); |
| 111 | time_measurement_context.cycle_num = 0; |
| 112 | } |
| 113 | else |
| 114 | { |
| 115 | ++time_measurement_context.cycle_num; |
| 116 | } |
| 117 | } |