Hi,
i have an rpi5 with passive cooling , in this case i have an socket loop they runs free unblocked, each accept runs with more then 200Khz per loop, so i reduce the cycle time to accept clients with usleep().
For normal usleep give back the CPU Load and the pi can come to cool down.
But, the effect is, if an client has become an sock via accept, it runs over many hours thermal normal.
if the client disconnect, the temperature falling for 5 minutes down, and then they will fast groving without connected clients and this in a reduced wait loop with only 50Hz to wait for new sock clients. (Some usleep is active why heating now ?
My Accept Loop is under construction and looks like this :
void *CWebServer::RunHttp(void* ptr)
{
CWebServer *pSvr((CWebServer *)ptr);
CWebSock *pWebSvr(new CWebSock());
sockaddr incaddr = { 0 };
socklen_t inclen(sizeof(sockaddr_in));
pthread_t thid;
int interval(4), newsock(-1), tempcf(1),maxtemp(50),loops(0);//secs
uint64_t ti(vcos_getmicrosecs64()), lastti(ti),lastuse(ti);
uint32_t uMaxThread(pSvr->m_maxcpu), uIdle(0), uNsock(0), uConnCnt(0), uDcnt(0), numSock(0);
pthread_attr_t tattr; pthread_attr_init(&tattr);
sched_param param; pthread_attr_getschedparam(&tattr, ¶m);
//https://stackoverflow.com/questions/3649281/how-to-increase-thread-priority-in-pthreads
//SCHED_OTHER the standard round - robin time - sharing policy;
//SCHED_BATCH for "batch" style execution of processes; and
//SCHED_IDLE for running very low priority background jobs.
//Real - time scheduling policies :
//SCHED_FIFO a first - in, first - out policy; and
//SCHED_RR a round - robin policy.
param.sched_priority = SCHED_IDLE;
pthread_attr_setschedparam(&tattr, ¶m);
pthread_attr_setschedpolicy(&tattr, SCHED_IDLE);
if (!pWebSvr->Listen(pSvr->m_portHttp))
{
puts("CWebServer::RunHttp Failed to start Listen");
pSvr->m_portHttp = 0; //end
}
while (pSvr->m_portHttp)//this in an high frequency socket loop, we must reduce em by start as idle priority (slowest) else overheating
{
ti = vcos_getmicrosecs64(), loops++;
if ((newsock = accept(pWebSvr->s_socket, &incaddr, (socklen_t*)&inclen)) > -1)
{
if (!pthread_create(&thid, &tattr, RequestHttp, (void*) new CWebSock(newsock, (void*)pSvr)))
pthread_detach(thid);//underpoll
}
usleep(1000 * 10);
if ((ti - lastti) > (interval*(1000*1000)))//4s
{
if (pSvr->Chkfiles(".lua"))
puts("File .lua was changed");
std::ifstream piCpuTempFile;piCpuTempFile.open("/sys/class/thermal/thermal_zone0/temp");
std::stringstream buffer;buffer << (piCpuTempFile.rdbuf());piCpuTempFile.close();
float temp(std::stof(buffer.str()) / 1000);
float fps((float)gSockCnt / (float)interval);
float usemem = get_phys_pages() * (sysconf(_SC_PAGE_SIZE)) - (get_avphys_pages() * sysconf(_SC_PAGE_SIZE));
printf("Fps=%0.1f [Hz] Rx=%0.1f [Kb/s] Tx=%0.1f [Mb/s] Temp=%0.1f [C] Mem=%0.1f [Mb] FrmNotSnd=%d [n/s] AccFrq=%0.1f [Hz]\r\n",
fps, ((gRxCnt / (float)interval) / 1024.0f), ((gTxCnt / (float)interval) / 1024.0f) / 1024.0f, temp, (usemem / 1024.0f) / 1024.0f, (pSvr->m_FailSend / interval), ((float)loops / (float)interval));
if (temp > maxtemp)//alarm
{
printf("\033[0;31mTemp=%0.1f \033[0mstrating thermal reduction Ceff=%d\r\n", temp, tempcf); //Display Hello in red
lastuse = 0;
tempcf = 1+(temp - maxtemp)*2;
}else if (fps > 0)//prepare cool down cpu temparature phase
lastuse = ti, tempcf=1;
pSvr->m_FailSend = 0;
gSockCnt = 0;
gRxCnt = 0;
gTxCnt = 0;
loops = 0;
lastti = ti;
}
if ((ti - lastuse) > (1000 * 1000)*10)//10 secs no activity start cool down temperatur controller
usleep(1000 * (10 * tempcf)); // sleeps to bring down cpu temp (10 is to less !)
}
shutdown(pWebSvr->s_socket, SHUT_RDWR);//server extra close
pWebSvr->Close();
puts("CWebServer::RunHttp terminated");
return 0;
}
Alles anzeigen
The question is, why the unblocked Socket runs after period of idle into hight temperature ?
Without watching he will run empty with sleep into 80C° but it runs normal with 38C° if an client use the socket.
After discon the socket , the temperature will incrase into termal self destruction, after 60C° The socket stops working vor new clients complettly.
If i turn on a Fan the situation goe's after some minutes into normal state, what is damming heating nothing is runs SLEEP give not up CPU Load ?
Thx for any helps same on rpi 3 runs without problems.
Output of this loop:
Temp=51.2 strating thermal reduction Ceff=3
Fps=0.0 [Hz] Rx=0.0 [Kb/s] Tx=0.0 [Mb/s] Temp=51.2 [C] Mem=643.8 [Mb] FrmNotSnd=0 [n/s] AccFrq=25.0 [Hz]
Temp=51.2 strating thermal reduction Ceff=3
CWebServer::RunHttp terminated
thx