|  | @@ -58,11 +58,65 @@ struct profiler {
 | 
		
	
		
			
			| 58 | 58 |  #define __profiler
 | 
		
	
		
			
			| 59 | 59 |  #endif
 | 
		
	
		
			
			| 60 | 60 |  
 | 
		
	
		
			
			|  | 61 | +extern unsigned long profile_excluded;
 | 
		
	
		
			
			|  | 62 | +
 | 
		
	
		
			
			| 61 | 63 |  extern void profile_update ( struct profiler *profiler, unsigned long sample );
 | 
		
	
		
			
			| 62 | 64 |  extern unsigned long profile_mean ( struct profiler *profiler );
 | 
		
	
		
			
			| 63 | 65 |  extern unsigned long profile_variance ( struct profiler *profiler );
 | 
		
	
		
			
			| 64 | 66 |  extern unsigned long profile_stddev ( struct profiler *profiler );
 | 
		
	
		
			
			| 65 | 67 |  
 | 
		
	
		
			
			|  | 68 | +/**
 | 
		
	
		
			
			|  | 69 | + * Get start time
 | 
		
	
		
			
			|  | 70 | + *
 | 
		
	
		
			
			|  | 71 | + * @v profiler		Profiler
 | 
		
	
		
			
			|  | 72 | + * @ret started		Start time
 | 
		
	
		
			
			|  | 73 | + */
 | 
		
	
		
			
			|  | 74 | +static inline __attribute__ (( always_inline )) unsigned long
 | 
		
	
		
			
			|  | 75 | +profile_started ( struct profiler *profiler ) {
 | 
		
	
		
			
			|  | 76 | +
 | 
		
	
		
			
			|  | 77 | +	/* If profiling is active then return start time */
 | 
		
	
		
			
			|  | 78 | +	if ( PROFILING ) {
 | 
		
	
		
			
			|  | 79 | +		return ( profiler->started + profile_excluded );
 | 
		
	
		
			
			|  | 80 | +	} else {
 | 
		
	
		
			
			|  | 81 | +		return 0;
 | 
		
	
		
			
			|  | 82 | +	}
 | 
		
	
		
			
			|  | 83 | +}
 | 
		
	
		
			
			|  | 84 | +
 | 
		
	
		
			
			|  | 85 | +/**
 | 
		
	
		
			
			|  | 86 | + * Get stop time
 | 
		
	
		
			
			|  | 87 | + *
 | 
		
	
		
			
			|  | 88 | + * @v profiler		Profiler
 | 
		
	
		
			
			|  | 89 | + * @ret stopped		Stop time
 | 
		
	
		
			
			|  | 90 | + */
 | 
		
	
		
			
			|  | 91 | +static inline __attribute__ (( always_inline )) unsigned long
 | 
		
	
		
			
			|  | 92 | +profile_stopped ( struct profiler *profiler ) {
 | 
		
	
		
			
			|  | 93 | +
 | 
		
	
		
			
			|  | 94 | +	/* If profiling is active then return start time */
 | 
		
	
		
			
			|  | 95 | +	if ( PROFILING ) {
 | 
		
	
		
			
			|  | 96 | +		return ( profiler->stopped + profile_excluded );
 | 
		
	
		
			
			|  | 97 | +	} else {
 | 
		
	
		
			
			|  | 98 | +		return 0;
 | 
		
	
		
			
			|  | 99 | +	}
 | 
		
	
		
			
			|  | 100 | +}
 | 
		
	
		
			
			|  | 101 | +
 | 
		
	
		
			
			|  | 102 | +/**
 | 
		
	
		
			
			|  | 103 | + * Get elapsed time
 | 
		
	
		
			
			|  | 104 | + *
 | 
		
	
		
			
			|  | 105 | + * @v profiler		Profiler
 | 
		
	
		
			
			|  | 106 | + * @ret elapsed		Elapsed time
 | 
		
	
		
			
			|  | 107 | + */
 | 
		
	
		
			
			|  | 108 | +static inline __attribute__ (( always_inline )) unsigned long
 | 
		
	
		
			
			|  | 109 | +profile_elapsed ( struct profiler *profiler ) {
 | 
		
	
		
			
			|  | 110 | +
 | 
		
	
		
			
			|  | 111 | +	/* If profiling is active then return elapsed time */
 | 
		
	
		
			
			|  | 112 | +	if ( PROFILING ) {
 | 
		
	
		
			
			|  | 113 | +		return ( profile_stopped ( profiler ) -
 | 
		
	
		
			
			|  | 114 | +			 profile_started ( profiler ) );
 | 
		
	
		
			
			|  | 115 | +	} else {
 | 
		
	
		
			
			|  | 116 | +		return 0;
 | 
		
	
		
			
			|  | 117 | +	}
 | 
		
	
		
			
			|  | 118 | +}
 | 
		
	
		
			
			|  | 119 | +
 | 
		
	
		
			
			| 66 | 120 |  /**
 | 
		
	
		
			
			| 67 | 121 |   * Start profiling
 | 
		
	
		
			
			| 68 | 122 |   *
 | 
		
	
	
		
			
			|  | @@ -74,7 +128,23 @@ profile_start_at ( struct profiler *profiler, unsigned long started ) {
 | 
		
	
		
			
			| 74 | 128 |  
 | 
		
	
		
			
			| 75 | 129 |  	/* If profiling is active then record start timestamp */
 | 
		
	
		
			
			| 76 | 130 |  	if ( PROFILING )
 | 
		
	
		
			
			| 77 |  | -		profiler->started = started;
 | 
		
	
		
			
			|  | 131 | +		profiler->started = ( started - profile_excluded );
 | 
		
	
		
			
			|  | 132 | +}
 | 
		
	
		
			
			|  | 133 | +
 | 
		
	
		
			
			|  | 134 | +/**
 | 
		
	
		
			
			|  | 135 | + * Stop profiling
 | 
		
	
		
			
			|  | 136 | + *
 | 
		
	
		
			
			|  | 137 | + * @v profiler		Profiler
 | 
		
	
		
			
			|  | 138 | + * @v stopped		Stop timestamp
 | 
		
	
		
			
			|  | 139 | + */
 | 
		
	
		
			
			|  | 140 | +static inline __attribute__ (( always_inline )) void
 | 
		
	
		
			
			|  | 141 | +profile_stop_at ( struct profiler *profiler, unsigned long stopped ) {
 | 
		
	
		
			
			|  | 142 | +
 | 
		
	
		
			
			|  | 143 | +	/* If profiling is active then record end timestamp and update stats */
 | 
		
	
		
			
			|  | 144 | +	if ( PROFILING ) {
 | 
		
	
		
			
			|  | 145 | +		profiler->stopped = ( stopped - profile_excluded );
 | 
		
	
		
			
			|  | 146 | +		profile_update ( profiler, profile_elapsed ( profiler ) );
 | 
		
	
		
			
			|  | 147 | +	}
 | 
		
	
		
			
			| 78 | 148 |  }
 | 
		
	
		
			
			| 79 | 149 |  
 | 
		
	
		
			
			| 80 | 150 |  /**
 | 
		
	
	
		
			
			|  | @@ -91,32 +161,29 @@ profile_start ( struct profiler *profiler ) {
 | 
		
	
		
			
			| 91 | 161 |  }
 | 
		
	
		
			
			| 92 | 162 |  
 | 
		
	
		
			
			| 93 | 163 |  /**
 | 
		
	
		
			
			| 94 |  | - * Record profiling result
 | 
		
	
		
			
			|  | 164 | + * Stop profiling
 | 
		
	
		
			
			| 95 | 165 |   *
 | 
		
	
		
			
			| 96 | 166 |   * @v profiler		Profiler
 | 
		
	
		
			
			| 97 |  | - * @v stopped		Stop timestamp
 | 
		
	
		
			
			| 98 | 167 |   */
 | 
		
	
		
			
			| 99 | 168 |  static inline __attribute__ (( always_inline )) void
 | 
		
	
		
			
			| 100 |  | -profile_stop_at ( struct profiler *profiler, unsigned long stopped ) {
 | 
		
	
		
			
			|  | 169 | +profile_stop ( struct profiler *profiler ) {
 | 
		
	
		
			
			| 101 | 170 |  
 | 
		
	
		
			
			| 102 | 171 |  	/* If profiling is active then record end timestamp and update stats */
 | 
		
	
		
			
			| 103 |  | -	if ( PROFILING ) {
 | 
		
	
		
			
			| 104 |  | -		profiler->stopped = stopped;
 | 
		
	
		
			
			| 105 |  | -		profile_update ( profiler, ( stopped - profiler->started ) );
 | 
		
	
		
			
			| 106 |  | -	}
 | 
		
	
		
			
			|  | 172 | +	if ( PROFILING )
 | 
		
	
		
			
			|  | 173 | +		profile_stop_at ( profiler, profile_timestamp() );
 | 
		
	
		
			
			| 107 | 174 |  }
 | 
		
	
		
			
			| 108 | 175 |  
 | 
		
	
		
			
			| 109 | 176 |  /**
 | 
		
	
		
			
			| 110 |  | - * Record profiling result
 | 
		
	
		
			
			|  | 177 | + * Exclude time from other ongoing profiling results
 | 
		
	
		
			
			| 111 | 178 |   *
 | 
		
	
		
			
			| 112 | 179 |   * @v profiler		Profiler
 | 
		
	
		
			
			| 113 | 180 |   */
 | 
		
	
		
			
			| 114 | 181 |  static inline __attribute__ (( always_inline )) void
 | 
		
	
		
			
			| 115 |  | -profile_stop ( struct profiler *profiler ) {
 | 
		
	
		
			
			|  | 182 | +profile_exclude ( struct profiler *profiler ) {
 | 
		
	
		
			
			| 116 | 183 |  
 | 
		
	
		
			
			| 117 |  | -	/* If profiling is active then record end timestamp and update stats */
 | 
		
	
		
			
			|  | 184 | +	/* If profiling is active then update accumulated excluded time */
 | 
		
	
		
			
			| 118 | 185 |  	if ( PROFILING )
 | 
		
	
		
			
			| 119 |  | -		profile_stop_at ( profiler, profile_timestamp() );
 | 
		
	
		
			
			|  | 186 | +		profile_excluded += profile_elapsed ( profiler );
 | 
		
	
		
			
			| 120 | 187 |  }
 | 
		
	
		
			
			| 121 | 188 |  
 | 
		
	
		
			
			| 122 | 189 |  #endif /* _IPXE_PROFILE_H */
 |