choose_freq分析

本文详细解析了CPU频率调节过程中的关键步骤,包括选择频率、调整负载和目标频率的确定,以及循环迭代的过程。通过具体例子展示了如何在不同负载条件下进行频率调整。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

choose_freq分析
1 800000:85 998400:90 1094400:80 1190400:80 1248000:80 1305600:80
例子1:  loadadjfreq=cpu_load*pcpu->policy->cur=92*998400
循环1:
   prevfreq = freq=998400;
   tl=90(998400:90) 通过当前频率找到下一级load
   loadadjfreq / tl=1020500
cpufreq_frequency_table_target: start
    target_freq=1020500
    CPUFREQ_RELATION_L
    freq=800,suboptimal.frequency = 800 suboptimal.driver_data=0;
    freq=998.4,suboptimal.frequency = 998.4 suboptimal.driver_data=1;
    freq=1094400,optimal.frequency = 1094400 optimal.driver_data=2
    freq=1190400  1248000  1305600(不起作用)  optimal.frequency = 1094400 i=5
    *index = optimal.driver_data=2;
cpufreq_frequency_table_target: end
    freq=1094400
    freqmin = prevfreq=998400;
    freqmax = UINT_MAX;

while (freq != prevfreq)进入循环2:
   prevfreq = freq=1094400;
   tl=80(1094400:80) 通过当前频率找到下一级load
   loadadjfreq / tl=92*998400/80=1148160
cpufreq_frequency_table_target: start
    target_freq=1148160
    CPUFREQ_RELATION_L
    freq=800,suboptimal.frequency = 800 suboptimal.driver_data=0;
    freq=998.4,suboptimal.frequency = 998.4 suboptimal.driver_data=1;
    freq=1094400,optimal.frequency = 1094400 optimal.driver_data=2
    freq=1190400  1248000  1305600(不起作用)  optimal.frequency = 1094400 i=5
    *index = optimal.driver_data=2;
cpufreq_frequency_table_target: end
    freq=1094400
    freqmin = prevfreq=1094400;
    freqmax = UINT_MAX;
while (freq != prevfreq)跳出循环


例子2:  loadadjfreq=cpu_load*pcpu->policy->cur=60*1190400

1 800000:85 998400:90 1094400:80 1190400:80 1248000:80 1305600:80

循环1:
   prevfreq = freq=1190400;
   tl=80(1190400:80) 通过当前频率找到下一级load
   loadadjfreq / tl=892800
cpufreq_frequency_table_target: start
    target_freq=892800
    CPUFREQ_RELATION_L
    freq=800,suboptimal.frequency = 800 suboptimal.driver_data=0;
    freq=998.4,optimal.frequency = 998.4 suboptimal.driver_data=1;
    freq=1094400 1190400  1248000  1305600(不起作用)  optimal.frequency = 1094400 i=5
    *index = optimal.driver_data=1;
cpufreq_frequency_table_target: end
    freq=998.400
    freqmax = prevfreq=1190400;    freqmin = 0;
    freqmax = UINT_MAX;

while (freq != prevfreq)进入循环2:


   prevfreq = freq=998.400;
   tl=90(998400:90) 通过当前频率找到下一级load
   loadadjfreq / tl=60*1190400/90=793600
cpufreq_frequency_table_target: start
    target_freq=793600
    CPUFREQ_RELATION_L
    freq=800000,optimal.frequency = 800 optimal.driver_data=0;
    freq=***1190400  1248000  1305600(不起作用)  optimal.frequency = 1094400 i=5
    *index = optimal.driver_data=0;
cpufreq_frequency_table_target: end
    freq=800000
    freqmin = 0;
    freqmax = 998400;

while (freq != prevfreq)进入循环3:


   prevfreq = freq=800000;
   tl=85(800000:85) 通过当前频率找到下一级load
   loadadjfreq / tl=60*1190400/85=840.282
cpufreq_frequency_table_target: start
    target_freq=840.282
    CPUFREQ_RELATION_L
    freq=800,suboptimal.frequency = 800 suboptimal.driver_data=0;
    freq=998.400,optimal.frequency = 998.400 suboptimal.driver_data=1;
    freq=1094400 1190400  1248000  1305600(不起作用)  optimal.frequency = 1094400 i=5
    *index = optimal.driver_data=1;
cpufreq_frequency_table_target: end
    freq=998.400
    freqmin = prevfreq = 800000;
    freqmax = 998400;
    进入if (freq >= freqmax)
cpufreq_frequency_table_target: start
    target_freq=freqmax-1=998339
    CPUFREQ_RELATION_H
    freq=800.000,optimal.frequency = 800.000 optimal.driver_data =0;
    freq=998.4,suboptimal.frequency = 998.4 suboptimal.driver_data=1;
    freq=1094400 1190400  1248000  1305600(不起作用)  suboptimal.frequency = 1094400 i=5
    *index = optimal.driver_data=0;
cpufreq_frequency_table_target: end
    freq=800000
    freqmin = 800000;
    freq=freqmax = 998400;
跳出循环
The whole source code can be downloaded from our download center. /******************************************************************************* Function Name : main Description : Main program. Input : None Output : None Return : None *****************************************************************************/ void main(void) { ENTR_CRT_SECTION(); / Setup STM32 system (clock, PLL and Flash configuration) / SystemInit(); EXT_CRT_SECTION(); // Choose your Slot (SPI1, SPI2) void Bus_Type = SPI1; / controlled loop / while (Dummy_var!=11) // To control the loop, e.g. (Dummy_var!=7) { if (Dummy_var10) Dummy_var=0; // Infinite loop if(configured_trueFALSE) { configured_true = TRUE; SPIx_GPIOs_Init(Bus_Type); SPIx_Interface_Init(Bus_Type); #ifdef EMBEDDED_SRAM Embed_SRAM_Init(); #endif Ext_Interrupt_Init(); gp22_send_1byte(Bus_Type, Power_On_Reset); Dly100us((void)5); // 500 us wait for GP22 // Setting of the Configuration Registers // CR0: DIV_CLKHS = 2, START_CLKHS = 1, CALIBRATE = 0, MESSB2 = 0, NEG_STOP = NEGSTART = 0, … Register_0 = 0x00240000; // NO_CAL_AUTO = 0 Register_0_NO_CAL = 0x00241000; // NO_CAL_AUTO = 1 // CR1: HITIN2 = 1, HITIN1 = 1, … Register_1 = 0x19490000; // EN_FAST_INIT = 0 Register_1_FAST = 0x19C90000; // EN_FAST_INIT = 1 // CR2: EN_INT, RFEDGE1 = RFEDGE2 = 0, … // (NOTE: EN_INT = b111, it doesn’t work with using EN_FAST_INT) Register_2 = 0xA0000000; // EN_INT = Timeout(8) _ End HITs(4) _ ALU interrupt(2) // CR3: … Register_3 = 0x00000000; // CR4: ... Register_4 = 0x20000000; // CR5: CON_FIRE = b000, EN_STARTNOISE = 1, ... Register_5 = 0x10000000; // CR6: QUAD_RES = 0, ... Register_6 = 0x00000000; // Writing to the configuration registers (CR) gp22_wr_config_reg(Bus_Type, 0x80, Register_0_NO_CAL); gp22_wr_config_reg(Bus_Type, 0x81, Register_1_FAST); gp22_wr_config_reg(Bus_Type, 0x82, Register_2); gp22_wr_config_reg(Bus_Type, 0x83, Register_3); gp22_wr_config_reg(Bus_Type, 0x84, Register_4); gp22_wr_config_reg(Bus_Type, 0x85, Register_5); gp22_wr_config_reg(Bus_Type, 0x86, Register_6); } // ......................................................................... // ...START_CAL_RESONATOR..Calibrate High Speed Clock....................... // ...START_CAL_TDC.....Update the CAL2- and CAL1-Value..................... // ...................Laser Rangefinder Measurement CYCLE............LOOP... // .........................Caluculate Result Values........................ N_Measure_Cycles = 10000; diff_Cal2_Cal1_old = diff_Cal2_Cal1_new; if((Dummy_var==0) | (Dummy_var==10)) { //-------------------------------------------------------------------------- // Start Calibrate High Speed Clock Cycle (-->SLOW) // Important Note: NO_CAL_AUTO and EN_FAST_INIT need to be cleared! gp22_wr_config_reg(Bus_Type, 0x80, Register_0); // NO_CAL_AUTO = 0 gp22_wr_config_reg(Bus_Type, 0x81, Register_1); // EN_FAST_INIT = 0 gp22_send_1byte(Bus_Type, Init); gp22_send_1byte(Bus_Type, Start_Cal_Resonator); // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); //Calculate Correction factor //The time interval to be measured is set by ANZ_PER_CALRES //which defines the number of periods of the 32.768 kHz clock: //2 periods = 61.03515625 µs CLKHS_freq_corr_fact = 61.03515625/ gp22_read_n_bytes_int(Bus_Type, 2, 0xB0, 0x00) * CLKHS_freq; // read only two bytes printf("\n Correction factor for clock = %1.4f\n", CLKHS_freq_corr_fact); CLKHS_freq_cal = CLKHS_freq * CLKHS_freq_corr_fact; // Calibrated Clock frequency //-------------------------------------------------------------------------- // Start Separate Calibration Measurement Cycle // Important Note: EN_INT = End HITs gp22_wr_config_reg(Bus_Type, 0x82, 0x40000000); // End HITs gp22_send_1byte(Bus_Type, Init); gp22_send_1byte(Bus_Type, Start_Cal_TDC); // update calibration data // Note: // The calibration data are not addressed directly after the calibration // measurement but after the next regular measurement; // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); // Important Note: After Separate Calibration Measurement Cycle // EN_INT = ALU interrupt gp22_wr_config_reg(Bus_Type, 0x82, Register_2); // Timeout + ALU interrupt //-------------------------------------------------------------------------- // 1st ToF Measurement plus calibration data readout // Note: (NO_CAL_AUTO = 0 / EN_FAST_INIT = 0) --> SLOW gp22_send_1byte(Bus_Type, Init); //Trigger pulse laser // SetPortHigh; GPIO_SetBits(GPIOD, GPIO_Pin_8); // Output HIGH // SetPortLow; GPIO_ResetBits(GPIOD, GPIO_Pin_8); // Output LOW // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); // First regular measurement (to readout calibration data) RAW_Result_int = gp22_read_n_bytes_int(Bus_Type,2,0xB0,0x00); // read only two bytes #ifdef EMBEDDED_SRAM Write_Emb_SRAM_uint32_t(RAW_Result_int); // writes the first value into SRAM #endif // printf("\n 1. Measured RAW Value = %u \n",RAW_Result_int); // RAW value // Check Status Register, next free result register // printf("Stat_Reg = 0x%04X \n",gp22_read_status_bytes(Bus_Type)); // readout the new calibration data from result register adr 0x01 gp22_wr_config_reg(Bus_Type, 0x81, 0x67490000); diff_Cal2_Cal1_new = gp22_read_n_bytes_int(Bus_Type,2,0xB0,0x01); // read only two bytes #ifdef EMBEDDED_SRAM Write_Emb_SRAM_uint32_t(diff_Cal2_Cal1_new); #endif } //-------------------------------------------------------------------------- // Calculate the real time after the hole first cycle loop while (diff_Cal2_Cal1_old != 0) { avg_diff_Cal2_Cal1 = (diff_Cal2_Cal1_new+diff_Cal2_Cal1_old) / 2; // printf("\n OLD Cal2-Cal1 RAW Value = %.0f \n",diff_Cal2_Cal1_old); // printf("\n NEW Cal2-Cal1 RAW Value = %.0f \n",diff_Cal2_Cal1_new); average_RAW_Result /= N_Measure_Cycles; // Used Formulas: // --------------------------------------------------- // T_ref // Time_Value = ----------- * measured_RAW_Value // Cal2-Cal1 // --------------------------------------------------- // velocity_of_light // Distance_Value = ------------------- * Time_Value // 2 // --------------------------------------------------- // For this Source Code would be a Reference Clock used with 1 MHz Time_Result = (average_RAW_Result/avg_diff_Cal2_Cal1) * 1000;//time [ns] Distance_Result = Time_Result / 6.671281904; //distance [m] printf("\n Time Measure Result (ToF) = %.3f ns\n",Time_Result); printf(" corresponds to %.3f m of Distance\n",Distance_Result); printf(" to reflected point after %u Measurements\n",N_Measure_Cycles); diff_Cal2_Cal1_old = 0; } //-------------------------------------------------------------------------- // if more than one measure cycle (-->FAST) average_RAW_Result = RAW_Result_int; // set first value of average_RAW_Result gp22_wr_config_reg(Bus_Type, 0x80, Register_0_NO_CAL); // NO_CAL_AUTO = 1 gp22_wr_config_reg(Bus_Type, 0x81, Register_1_FAST); // EN_FAST_INIT = 1 gp22_send_1byte(Bus_Type, Init); //-------------------------------------------------------------------------- // n'th ToF Measurement for (int i=2; i<=N_Measure_Cycles;i++) { //Trigger pulse laser // SetPortHigh; GPIO_SetBits(GPIOD, GPIO_Pin_8); // Output HIGH // SetPortLow; GPIO_ResetBits(GPIOD, GPIO_Pin_8); // Output LOW // Wait for INT Slot_x if (Bus_Type==SPI1) while (GPIO_ReadInputDataBit(GPIOD, GPIO_Pin_4)==1); if (Bus_Type==SPI2) while (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_11)==1); RAW_Result_int = gp22_read_n_bytes_int(Bus_Type,2,0xB0,0x00); // read only two bytes // printf(" %u. Measure RAW Value = %.0f \n",i,RAW_Result_int); // RAW value average_RAW_Result += RAW_Result_int; #ifdef EMBEDDED_SRAM Write_Emb_SRAM_uint32_t(RAW_Result_int); // writes the next values into SRAM #endif } printf("\nNEW CYCLE...\n"); Dummy_var++; // To Control the loop #ifdef EMBEDDED_SRAM // clear internal SRAM of µC sram_mem_offset = 0x0; #endif } // End while Dummy_var } //End main
最新发布
08-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值