/* * THERMAL "Monitoring Zone" definition: * - No constraint about Max CPU frequency (See scaling_max_freq) * - Select "conservative" (if available) CPU freq governor to avoid selecting higher frequency first * - Increase temperature monitoring rate (See update_rate) * - Thresholds configuration: * . High: Max = TEMP_ALERT_HIGH * . Low: Min = TEMP_MONITORING_LOW */ static void monitoring_zone(void) { LOGD("OMAP CPU THERMAL - Monitoring Zone (hot spot temp: %i)\n", cpu_temp); fflush(stdout); update_cpu_scaling_max_freq(nominal_cpu_scaling_max_freq); if (is_conservative_available == true) { update_cpu_scaling_governor("conservative"); #ifdef DEBUG LOGD("conservative governor is available\n"); fflush(stdout); #endif } else { #ifdef DEBUG LOGD("conservative governor is not available\n"); fflush(stdout); #endif } update_omap_rate(FAST_TEMP_MONITORING_RATE); update_thresholds(config_file.omap_cpu_threshold_alert, config_file.omap_cpu_threshold_monitoring - HYSTERESIS_VALUE); print_latest_settings(); }
void pvcompand_float(t_pvcompand *x, double f) // Look at floats at inlets { int inlet = x->x_obj.z_in; if (inlet == 1) { x->last_max_atten = x->max_atten = f; update_thresholds(x); } }
void pvcompand_init(t_pvcompand *x,short initialized) { int i; if(!power_of_two(x->overlap)) x->overlap = 4; if(!power_of_two(x->winfac)) x->winfac = 1; x->N = x->D * x->overlap; x->Nw = x->N * x->winfac; limit_fftsize(&x->N,&x->Nw,OBJECT_NAME); x->N2 = (x->N)>>1; x->Nw2 = (x->Nw)>>1; x->inCount = -(x->Nw); x->mult = 1. / (float) x->N; if(!initialized){ x->norml = 0; x->mute = 0; x->bypass = 0; x->thresh_interval = 1.0; x->last_max_atten = x->max_atten; x->atten_interval = 2.0 ; x->tstep = 1.0 ; x->gstep = 2.0 ; x->Wanal = (float *) getbytes(MAX_Nw * sizeof(float)); x->Wsyn = (float *) getbytes(MAX_Nw * sizeof(float)); x->Hwin = (float *) getbytes(MAX_Nw * sizeof(float)); x->input = (float *) getbytes(MAX_Nw * sizeof(float) ); x->buffer = (float *) getbytes(MAX_N * sizeof(float) ); x->channel = (float *) getbytes( (MAX_N+2) * sizeof(float) ); x->output = (float *) getbytes(MAX_N * sizeof(float) ); x->bitshuffle = (int *) getbytes(MAX_N * 2 * sizeof( int ) ); x->trigland = (float *) getbytes(MAX_N * 2 * sizeof( float ) ); x->thresh = (float *) getbytes(MAX_N * sizeof(float) ); x->atten = (float *) getbytes(MAX_N * sizeof(float) ); x->curthresh = (float *) getbytes(MAX_N * sizeof(float) ); } memset((char *)x->input,0,x->Nw * sizeof(float)); memset((char *)x->output,0,x->Nw * sizeof(float)); init_rdft( x->N, x->bitshuffle, x->trigland); makewindows( x->Hwin, x->Wanal, x->Wsyn, x->Nw, x->N, x->D); update_thresholds(x); }
/* * THERMAL "Alert Zone" definition: * - If the Panic Zone has never been reached, then * - Define constraint about Max CPU frequency (See scaling_max_freq) * if Current frequency < Max frequency, then select lower value for Max frequency * - Else keep the constraints set previously until temperature falls to Monitoring zone * - Select "conservative" (if available) CPU freq governor to avoid selecting higher frequency first * - Increase temperature monitoring rate (See update_rate) * - Thresholds configuration: * . High: Max = TEMP_PANIC_HIGH * . Low: Min = TEMP_ALERT_LOW */ static void alert_zone(void) { u32 current_freq; int i; LOGD("OMAP CPU THERMAL - Alert Zone (hot spot temp: %i)\n", cpu_temp); fflush(stdout); if (is_panic_zone_reached == false) { /* temperature rises and enters into ALERT zone */ current_freq = atoi(read_from_file( config_file.cpufreq_file_paths[CPUINFO_CUR_FREQ_PATH])); if (current_freq < current_scaling_max_freq) { #ifdef DEBUG LOGD("ALERT Zone: current_freq < current_scaling_max_freq\n"); #endif /* Identify the index of current_scaling_max_freq in the available_freq table */ for (i = 0; i < OPPS_NUMBER; i++) { if (current_scaling_max_freq == available_freq[i]) break; } /* Select the next lowest one from available_freq table */ update_cpu_scaling_max_freq(available_freq[i-1]); } } else { /* temperature falls from PANIC zone and enters into ALERT zone */ /* Do nothing here as we should wait until temperature falls again */ } if (is_conservative_available == true) { update_cpu_scaling_governor("conservative"); #ifdef DEBUG LOGD("conservative governor is available\n"); fflush(stdout); #endif } else { #ifdef DEBUG LOGD("conservative governor is not available\n"); fflush(stdout); #endif } update_omap_rate(FAST_TEMP_MONITORING_RATE); update_thresholds(config_file.omap_cpu_threshold_panic, config_file.omap_cpu_threshold_alert - HYSTERESIS_VALUE); print_latest_settings(); }
/* * THERMAL "Safe Zone" definition: * - No constraint about Max CPU frequency (See scaling_max_freq) * - No constraint about CPU freq governor (See scaling_governor) * - Normal temperature monitoring rate (See update_rate) * - Thresholds configuration: * . High = TEMP_MONITORING_HIGH * . Low = TEMP_MONITORING_LOW */ static void safe_zone(void) { LOGD("OMAP CPU THERMAL - Safe Zone (hot spot temp: %i)\n", cpu_temp); fflush(stdout); update_cpu_scaling_max_freq(nominal_cpu_scaling_max_freq); update_cpu_scaling_governor(nominal_cpu_scaling_governor); update_omap_rate(NORMAL_TEMP_MONITORING_RATE); update_thresholds(config_file.omap_cpu_threshold_monitoring, config_file.omap_cpu_threshold_monitoring - HYSTERESIS_VALUE); is_panic_zone_reached = false; print_latest_settings(); }
t_int *pvcompand_perform(t_int *w) { float sample, outsamp ; int i,j; float maxamp ; float fmult; float cutoff; float avr, new_avr, rescale; t_pvcompand *x = (t_pvcompand *) (w[1]); t_float *in = (t_float *)(w[2]); t_float *in2 = (t_float *)(w[3]); t_float *out = (t_float *)(w[4]); int n = (int)(w[5]); int inCount = x->inCount; float *Wanal = x->Wanal; float *Wsyn = x->Wsyn; float *input = x->input; float *Hwin = x->Hwin; float *buffer = x->buffer; float *channel = x->channel; float *output = x->output; int D = x->D; int I = D; int R = x->R; int Nw = x->Nw; int N = x->N ; int N2 = x-> N2; int Nw2 = x->Nw2; int *bitshuffle = x->bitshuffle; float *trigland = x->trigland; float mult = x->mult; int count = x->count; float *atten = x->atten; float *curthresh = x->curthresh; float *thresh = x->thresh; float max_atten = x->max_atten; if( x->mute ){ while( n-- ){ *out++ = 0.0; } return (w+6); } if( x->bypass ){ while( n-- ){ *out++ = *in++ * 0.5; // gain compensation } return (w+6); } #if MSP if( x->connected[1] ){ max_atten = *in2++ ; if(max_atten != x->last_max_atten) { x->last_max_atten = x->max_atten = max_atten; update_thresholds(x); } } #endif #if PD max_atten = *in2++ ; if(max_atten != x->last_max_atten) { x->last_max_atten = x->max_atten = max_atten; update_thresholds(x); } #endif inCount += D; for ( j = 0 ; j < Nw - D ; j++ ){ input[j] = input[j+D]; } for ( j = Nw - D; j < Nw; j++ ) { input[j] = *in++; } fold( input, Wanal, Nw, buffer, N, inCount ); rdft( N, 1, buffer, bitshuffle, trigland ); leanconvert(buffer, channel, N2); maxamp = 0.; avr = 0; for( i = 0; i < N; i+= 2 ){ avr += channel[i]; if( maxamp < channel[i] ){ maxamp = channel[i] ; } } if(count <= 1){ // post("count too low!"); count = 1; } for( i = 0; i < count; i++ ){ curthresh[i] = thresh[i]*maxamp ; } cutoff = curthresh[count-1]; new_avr = 0; for( i = 0; i < N; i += 2){ if( channel[i] > cutoff ){ j = count-1; while( channel[i] > curthresh[j] ){ j--; if( j < 0 ){ j = 0; break; } } channel[i] *= atten[j]; } new_avr += channel[i] ; } leanunconvert( channel,buffer, N2); rdft( N, -1, buffer, bitshuffle, trigland ); overlapadd( buffer, N, Wsyn, output, Nw, inCount); if( x->norml ) { if( new_avr <= 0 ){ new_avr = .0001; } rescale = avr / new_avr ; mult *= rescale ; } else { mult *= pvcompand_ampdb( max_atten * -.5); ; } for ( j = 0; j < D; j++ ){ *out++ = output[j] * mult; } for ( j = 0; j < Nw - D; j++ ) output[j] = output[j+D]; for ( j = Nw - D; j < Nw; j++ ) output[j] = 0.; /* restore state variables */ x->inCount = inCount % Nw; return (w+6); }
virtual void externalTransition(const vd::ExternalEventList &events, vd::Time time) override { double val, shifting_factor; int cnt; if (events.size() > 1) Trace(context(), 6, "Warning: %s got multiple events at date: %f\n", getModelName().c_str(), time); auto it = events.begin(); while (it != events.end()) { val = it->getMap().getDouble("d_val"); if (INIT == m_state) { init_step_number_and_offset(val); update_thresholds(); m_state = RESPONSE; } else { cnt = 0; if ((val > m_upthreshold) || (val < m_downthreshold)) Trace(context(), 6, "%s: treating out of bonds val: %f " "(quantizer interval : [%f,%f] at date: %f", getModelName().c_str(), val, m_downthreshold, m_upthreshold, time); while ((val >= m_upthreshold) || (val <= m_downthreshold)) { cnt++; if (val >= m_upthreshold) { m_step_number++; } else { m_step_number--; } switch (m_adapt_state) { case IMPOSSIBLE: update_thresholds(); break; case POSSIBLE: if (val >= m_upthreshold) { store_change(m_step_size, time); } else { store_change(-m_step_size, time); } shifting_factor = shift_quanta(); if (0 > shifting_factor) throw vu::ModellingError( "Bad shifting value (value : %f, " "should be strictly positive)\n", shifting_factor); if (1 < shifting_factor) throw vu::ModellingError( "Bad shifting value ( value : %f, " "should be less than 1)\n", shifting_factor);; if ((0 != shifting_factor) && (1 != shifting_factor)) { if (val >= m_upthreshold) { update_thresholds(shifting_factor, DOWN); } else { update_thresholds(shifting_factor, UP); } Trace(context(), 6, "Quantifier %s new quantas while treating new val %f at date %f", getModelName().c_str(), val, time); Trace(context(), 6, "Quantizer interval: [%f, %f], amplitude: %f " "(default amplitude: %f)", m_downthreshold, m_upthreshold, (m_upthreshold - m_downthreshold), (2 * m_step_size)); Trace(context(), 6, "Quantifier %s shifting : %f", getModelName().c_str(), shifting_factor); m_adapt_state = DONE; } else { update_thresholds(); } break; case DONE: // equiv to reinit init_step_number_and_offset(val); // archive.resize(0); m_adapt_state = POSSIBLE; update_thresholds(); break; } } if (cnt > 1) Trace(context(), 6, "Warning : in %s multiple quanta change" " at date : %f %d\n", getModelName().c_str(), time, cnt); if (0 == cnt) Trace(context(), 6, "Warning : in %s useless ext transition" "call: no quanta change! input val %f (quantizer " "interval : [%f,%f] at date %f\n", getModelName().c_str(), val, m_downthreshold, m_upthreshold, time); } ++it; } m_state = RESPONSE; }
/* * THERMAL "Panic Zone" definition: * - Force CPU frequency to a "safe frequency" (See scaling_setspeed and scaling_max_freq) * . Select userspace CPUFreq governor to force the frequency/OPP update (See scaling_governor) * . Force the CPU frequency to a “safe” frequency (See scaling_setspeed) * . Limit max CPU frequency to the “safe” frequency (See scaling_max_freq) * . Select "conservative" (if available) CPU freq governor * - Increase temperature monitoring rate (See update_rate) * - Thresholds configuration: * . High: Max = TEMP_FATAL_HIGH * . Low: Min = TEMP_PANIC_LOW */ static void panic_zone(void) { char *governor; int i; u32 panic_zone_cpu_freq; u32 current_freq; int threshold_fatal; LOGD("OMAP CPU THERMAL - Panic Zone (hot spot temp: %i)\n", cpu_temp); fflush(stdout); /* Read current frequency */ current_freq = atoi(read_from_file( config_file.cpufreq_file_paths[CPUINFO_CUR_FREQ_PATH])); /* Identify the index of current frequency in the available_freq table */ for (i = 0; i < OPPS_NUMBER; i++) { if (current_freq == available_freq[i]) break; } /* Select the next lowest one from available_freq table */ panic_zone_cpu_freq = available_freq[i-1]; if (is_conservative_available == true) { governor = "conservative"; #ifdef DEBUG LOGD("conservative governor is available\n"); fflush(stdout); #endif } else { governor = read_from_file( config_file.cpufreq_file_paths[SCALING_GOVERNOR_PATH]); /* * FIXME : Should be fully useless. But without this, the * value of governor is not correct when used */ if (strcmp(governor, ("hotplug")) == 0) governor = "hotplug"; else if (strcmp(governor, ("conservative")) == 0) governor = "conservative"; else if (strcmp(governor, ("ondemand")) == 0) governor = "ondemand"; else if (strcmp(governor, ("userspace")) == 0) governor = "userspace"; else if (strcmp(governor, ("performance")) == 0) governor = "performance"; #ifdef DEBUG LOGD("initial governor is %s\n", governor); fflush(stdout); #endif } /* * Force the new frequency through userspace governor * and come back to the original cpufreq governor */ update_cpu_scaling_governor("userspace"); update_cpu_scaling_set_speed(panic_zone_cpu_freq); update_cpu_scaling_max_freq(panic_zone_cpu_freq); update_cpu_scaling_governor(governor); update_omap_rate(FAST_TEMP_MONITORING_RATE); /* * Safety mechanism in panic zone to avoid reaching fatal zone: * Define a threshold between TPanic and TFatal to detect if the * temperature still rises after forcing lower frequency * Select lowest OPP when entering into Pre-Fatal Zone */ threshold_fatal = ((config_file.omap_cpu_threshold_panic + OMAP_CPU_THRESHOLD_FATAL) / 2); if (cpu_temp >= threshold_fatal) { threshold_fatal = OMAP_CPU_THRESHOLD_FATAL; update_cpu_scaling_governor("userspace"); update_cpu_scaling_set_speed(available_freq[0]); update_cpu_scaling_max_freq(available_freq[0]); update_cpu_scaling_governor(governor); #ifdef DEBUG LOGD("OMAP CPU THERMAL - Pre-Fatal Zone (hot spot temp: %i)\n", cpu_temp); fflush(stdout); #endif } update_thresholds(threshold_fatal, config_file.omap_cpu_threshold_panic - HYSTERESIS_VALUE); is_panic_zone_reached = true; print_latest_settings(); }